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

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

Loading…
Cancel
Save