v1.18.x
barisusakli 11 years ago
parent 835c58d27d
commit f463030e76

@ -113,13 +113,25 @@ module.exports = function(Categories) {
return; return;
} }
var keys = pids.map(function(pid) { var start = 0,
done = false,
batch = 50;
async.whilst(function() {
return !done;
}, function(next) {
var movePids = pids.slice(start, start + batch);
if (!movePids.length) {
done = true;
return next();
}
var keys = movePids.map(function(pid) {
return 'post:' + pid; return 'post:' + pid;
}); });
db.getObjectsFields(keys, ['timestamp'], function(err, postData) { db.getObjectsFields(keys, ['timestamp'], function(err, postData) {
if (err) { if (err) {
return winston.error(err.message); return next(err);
} }
var timestamps = postData.map(function(post) { var timestamps = postData.map(function(post) {
@ -128,17 +140,24 @@ module.exports = function(Categories) {
async.parallel([ async.parallel([
function(next) { function(next) {
db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pids, next); db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, movePids, next);
}, },
function(next) { function(next) {
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, pids, next); db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, movePids, next);
} }
], function(err) { ], function(err) {
if (err) { if (err) {
winston.error(err.message); return next(err);
} }
start += batch;
next();
}); });
}); });
}, function(err) {
if (err) {
winston.error(err.stack);
}
});
}); });
}; };

Loading…
Cancel
Save