added progress bars to all upgrade scripts processing posts:pid sorted set

v1.18.x
Julian Lam 8 years ago
parent 8fc6123230
commit 3022a1920b

@ -12,6 +12,7 @@ module.exports = {
timestamp: Date.UTC(2016, 0, 14), timestamp: Date.UTC(2016, 0, 14),
method: function (callback) { method: function (callback) {
var batch = require('../../batch'); var batch = require('../../batch');
var progress = this.progress;
batch.processSortedSet('posts:pid', function (ids, next) { batch.processSortedSet('posts:pid', function (ids, next) {
async.eachSeries(ids, function (id, next) { async.eachSeries(ids, function (id, next) {
@ -24,8 +25,11 @@ module.exports = {
} }
winston.verbose('processing pid: ' + postData.pid + ' uid: ' + postData.uid + ' votes: ' + postData.votes); winston.verbose('processing pid: ' + postData.pid + ' uid: ' + postData.uid + ' votes: ' + postData.votes);
db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next); db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next);
progress.incr();
}); });
}, next); }, next);
}, {}, callback); }, {
progress: progress,
}, callback);
}, },
}; };

@ -14,6 +14,8 @@ module.exports = {
var batch = require('../../batch'); var batch = require('../../batch');
var posts = require('../../posts'); var posts = require('../../posts');
var count = 0; var count = 0;
var progress = this.progress;
batch.processSortedSet('posts:pid', function (pids, next) { batch.processSortedSet('posts:pid', function (pids, next) {
winston.verbose('upgraded ' + count + ' posts'); winston.verbose('upgraded ' + count + ' posts');
count += pids.length; count += pids.length;
@ -43,8 +45,12 @@ module.exports = {
} else { } else {
next(); next();
} }
progress.incr();
}, next); }, next);
}, next); }, next);
}, {}, callback); }, {
progress: progress,
}, callback);
}, },
}; };

@ -12,9 +12,12 @@ module.exports = {
method: function (callback) { method: function (callback) {
function upgradePosts(next) { function upgradePosts(next) {
var batch = require('../../batch'); var batch = require('../../batch');
var progress = this.progress;
batch.processSortedSet('posts:pid', function (ids, next) { batch.processSortedSet('posts:pid', function (ids, next) {
async.each(ids, function (id, next) { async.each(ids, function (id, next) {
progress.incr();
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.rename('pid:' + id + ':users_favourited', 'pid:' + id + ':users_bookmarked', next); db.rename('pid:' + id + ':users_favourited', 'pid:' + id + ':users_bookmarked', next);
@ -34,7 +37,9 @@ module.exports = {
}, },
], next); ], next);
}, next); }, next);
}, {}, next); }, {
progress: progress,
}, next);
} }
function upgradeUsers(next) { function upgradeUsers(next) {

@ -13,12 +13,16 @@ module.exports = {
method: function (callback) { method: function (callback) {
var posts = require('../../posts'); var posts = require('../../posts');
var batch = require('../../batch'); var batch = require('../../batch');
var progress = this.progress;
batch.processSortedSet('posts:pid', function (ids, next) { batch.processSortedSet('posts:pid', function (ids, next) {
posts.getPostsFields(ids, ['pid', 'toPid', 'timestamp'], function (err, data) { posts.getPostsFields(ids, ['pid', 'toPid', 'timestamp'], function (err, data) {
if (err) { if (err) {
return next(err); return next(err);
} }
progress.incr();
async.eachSeries(data, function (postData, next) { async.eachSeries(data, function (postData, next) {
if (!parseInt(postData.toPid, 10)) { if (!parseInt(postData.toPid, 10)) {
return next(null); return next(null);
@ -30,6 +34,8 @@ module.exports = {
], next); ], next);
}, next); }, next);
}); });
}, {
progress: progress,
}, callback); }, callback);
}, },
}; };

@ -13,6 +13,7 @@ module.exports = {
var batch = require('../../batch'); var batch = require('../../batch');
var posts = require('../../posts'); var posts = require('../../posts');
var flags = require('../../flags'); var flags = require('../../flags');
var progress = this.progress;
batch.processSortedSet('posts:pid', function (ids, next) { batch.processSortedSet('posts:pid', function (ids, next) {
posts.getPostsByPids(ids, 1, function (err, posts) { posts.getPostsByPids(ids, 1, function (err, posts) {
@ -80,10 +81,14 @@ module.exports = {
} else { } else {
next(err); next(err);
} }
progress.incr();
}); });
}); });
}, next); }, next);
}); });
}, {
progress: this.progress,
}, callback); }, callback);
}, },
}; };

Loading…
Cancel
Save