Squashed commit of the following:
commit 7bd46afad7033a466626826d3e29610f41328510 Author: Julian Lam <julian@nodebb.org> Date: Thu Mar 15 15:41:36 2018 -0400 fixes #6363 commit 4b755d5801b2f6d70cea10516f88392708c72f61 Author: Julian Lam <julian@nodebb.org> Date: Thu Mar 15 15:24:12 2018 -0400 fixes #6362 commit 6035e75453a08aee0fef7ff59d57dd5c1e8f4ac9 Author: Julian Lam <julian@nodebb.org> Date: Thu Mar 15 15:07:23 2018 -0400 Fixes #6361v1.18.x
parent
8492a1586f
commit
5d2e6f0e8e
@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
var db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
var async = require('async');
|
||||
|
||||
module.exports = {
|
||||
name: 'Reformatting post diffs to be stored in lists and hash instead of single zset',
|
||||
timestamp: Date.UTC(2017, 2, 15),
|
||||
method: function (callback) {
|
||||
var progress = this.progress;
|
||||
|
||||
batch.processSortedSet('posts:pid', function (pids, next) {
|
||||
async.each(pids, function (pid, next) {
|
||||
db.getSortedSetRangeWithScores('post:' + pid + ':diffs', 0, -1, function (err, diffs) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!diffs || !diffs.length) {
|
||||
progress.incr();
|
||||
return next();
|
||||
}
|
||||
|
||||
// For each diff, push to list
|
||||
async.each(diffs, function (diff, next) {
|
||||
async.series([
|
||||
async.apply(db.delete.bind(db), 'post:' + pid + ':diffs'),
|
||||
async.apply(db.listPrepend.bind(db), 'post:' + pid + ':diffs', diff.score),
|
||||
async.apply(db.setObject.bind(db), 'diff:' + pid + '.' + diff.score, {
|
||||
pid: pid,
|
||||
patch: diff.value,
|
||||
}),
|
||||
], next);
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
progress.incr();
|
||||
return next();
|
||||
});
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
// Probably type error, ok to incr and continue
|
||||
progress.incr();
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
}, {
|
||||
progress: progress,
|
||||
}, callback);
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue