forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildSets.js
More file actions
63 lines (63 loc) · 2.18 KB
/
Copy pathbuildSets.js
File metadata and controls
63 lines (63 loc) · 2.18 KB
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
var async = require('async');
module.exports = function buildSets(db, redis, cb) {
console.log("rebuilding sets");
async.parallel({
//players in this set have their matches parsed
"trackedPlayers": function(cb) {
redis.keys("visit:*", function(err, result) {
var t = {};
result.forEach(function(redis_key) {
var account_id = redis_key.split(":")[1];
t[account_id] = true;
});
//console.log(t);
cb(err, t);
});
},
//users in this set have their matches added
"userPlayers": function(cb) {
db.select(['account_id']).from('players').whereNotNull('last_login').asCallback(function(err, docs) {
if (err) {
return cb(err);
}
var t = {};
docs.forEach(function(player) {
t[player.account_id] = true;
});
//console.log(t);
cb(err, t);
});
},
//users in this set are added to the trackedPlayers set
"donators": function(cb) {
db.select(['account_id']).from('players').where('cheese', '>', 0).asCallback(function(err, docs) {
if (err) {
return cb(err);
}
var t = {};
docs.forEach(function(player) {
t[player.account_id] = true;
});
//console.log(t);
cb(err, t);
});
}
}, function(err, result) {
if (err) {
console.log('error occurred during buildSets: %s', err);
return cb(err);
}
console.log('saving sets to redis');
for (var key in result) {
if (key === "trackedPlayers") {
//add donators to set
for (var key2 in result.donators) {
result.trackedPlayers[key2] = true;
}
}
redis.set(key, JSON.stringify(result[key]));
}
console.log('set build complete');
return cb(err);
});
};