Created
March 5, 2012 10:24
-
-
Save janjongboom/1977769 to your computer and use it in GitHub Desktop.
find activities c9 redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var Search = require("c9/dispatcher/search"); | |
module.exports.hotfix = function(config, infraredis, searchredis) { | |
Search.setDatabases(infraredis, searchredis); | |
var start = 0, end = 106000; | |
var aids = [] | |
for (var i = start; i <= end; i++) { | |
aids.push(i); | |
} | |
var pid = [ 150491 ]; | |
getActivities(infraredis, aids, function (err, activities) { | |
if (err) { | |
return console.log("getActivities", err); | |
} | |
console.log("Found " + activities.length + " entries", typeof activities[0].metadata, activities[0].metadata); | |
var matching = activities.filter(function (a) { | |
return a.subtype == "projectremoved" && pid.indexOf(a.metadata.pid) > -1; | |
}); | |
console.log("Filtered, now there are", matching.length); | |
if (matching > 20) return; | |
matching.forEach(function (m) { | |
console.log(m); | |
}); | |
}); | |
}; | |
function getActivities (infraredis, aids, callback) { | |
var _self = infraredis; | |
var commands = []; | |
if (!aids.length) | |
return callback(null, null); | |
for (var i = 0; i < aids.length; i++) { | |
var aid = aids[i]; | |
commands.push(["HMGET", "a/" + aid, "type", "subtype", "metadata", "uids", "date_add", "date_lch"]); | |
} | |
_self.client.multi(commands).exec(function(err, res) { | |
if (err) | |
return callback(err); | |
var activities = _self.fromMultiBulk(res); | |
var result = []; | |
for (i = 0; i < aids.length; i++) { | |
var activity = activities[i]; | |
if (!activity) continue; | |
var aid = parseInt(aids[i], 10); | |
result.push({ | |
"aid" : aid, | |
"type" : activity[0], | |
"subtype" : activity[1], | |
"metadata" : activity[2] && JSON.parse(activity[2]), | |
"uids" : activity[3].split(",").map(function(uid) { return parseInt(uid, 10); }), | |
"date_add" : activity[4], | |
"date_lch" : activity[5] | |
}); | |
} | |
callback(null, result); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment