forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play21.js
89 lines (75 loc) · 2.98 KB
/
play21.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
print("user.settings should not be an empty array, but an empty object");
db.user2.find({settings:{'$in':[{},[]]}}).forEach(function(user) {
db.user2.update({'_id': user['_id']}, {'$unset':{settings:true}});
});
print("user.roles should not be an empty array, but an empty object");
db.user2.find({roles:{'$in':[{},[]]}}).forEach(function(user) {
db.user2.update({'_id': user['_id']}, {'$unset':{roles:true}});
});
print("rename user.isChatBan -> user.troll");
db.user2.update({},{$rename:{isChatBan:'troll'}}, {multi:true});
print("add troll fields to the forum topics")
db.f_topic.find().forEach(function(topic) {
db.f_topic.update({'_id': topic['_id']}, { $set: {
troll: false,
updatedAtTroll: topic['updatedAt'],
nbPostsTroll: topic['nbPosts'],
lastPostIdTroll: topic['lastPostId']
}});
});
print("add troll fields to the forum categs")
db.f_categ.find().forEach(function(categ) {
db.f_categ.update({'_id': categ['_id']}, { $set: {
nbTopicsTroll: categ['nbTopics'],
nbPostsTroll: categ['nbPosts'],
lastPostIdTroll: categ['lastPostId']
}});
});
print("remove useless author names in forum posts")
db.f_post.update({author:{$exists:true},userId:{$exists:true}},{$unset:{author:true}},{multi:true});
print("mark all forum posts as not troll");
db.f_post.update({},{$set:{troll:false}}, {multi:true});
print("use troll field in forum post indexes")
db.f_post.dropIndex('topicId_1')
db.f_post.dropIndex('topicId_1_createdAt_1')
db.f_post.dropIndex('categId_1')
db.f_post.dropIndex('createdAt_-1')
db.f_post.ensureIndex({topicId: 1, troll: 1})
db.f_post.ensureIndex({topicId: 1, createdAt: 1, troll: 1})
db.f_post.ensureIndex({categId: 1, troll: 1})
db.f_post.ensureIndex({createdAt: -1, troll: 1})
print("use troll field in forum topic indexes")
db.f_topic.dropIndex('categId_1')
db.f_topic.dropIndex('categId_1_updatedAt_-1')
db.f_topic.ensureIndex({categId: 1, troll: 1})
db.f_topic.ensureIndex({categId: 1, updatedAt: -1, troll: 1})
print("user.settings.{chat,sound} should be a string");
['settings.chat', 'settings.sound'].forEach(function(name) {
[true, false].forEach(function(value) {
var sel = {}
sel[name] = value;
printjson(sel);
db.user2.find(sel).forEach(function(user) {
var up = {}
up[name] = value.toString();
printjson(up);
db.user2.update({'_id': user['_id']}, {'$set':up});
});
});
});
print('create relation collection');
db.createCollection('relation')
db.relation.ensureIndex({u1:1})
db.relation.ensureIndex({u2:1})
print('index forum post authors');
db.f_post.ensureIndex({userId:1})
print('create timeline_entry collection');
db.createCollection("timeline_entry",{capped:true,size:50000000})
db.timeline_entry.ensureIndex({user:1, date: -1});
db.timeline_entry.ensureIndex({type:1, date: -1});
// print("Reset lobby_room");
// db.lobby_room.drop();
// db.createCollection("lobby_room",{capped:true,size:50000})
// print("Reset lobby_entry");
// db.lobby_entry.drop();
// db.createCollection("lobby_entry",{capped:true,size:10000})