fix: #7519
parent
fb58e23914
commit
ed91d3f2c8
@ -0,0 +1,54 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
var db = require('../../database');
|
||||||
|
var batch = require('../../batch');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'Update moderation notes to hashes',
|
||||||
|
timestamp: Date.UTC(2018, 3, 5),
|
||||||
|
method: function (callback) {
|
||||||
|
var progress = this.progress;
|
||||||
|
|
||||||
|
batch.processSortedSet('users:joindate', function (ids, next) {
|
||||||
|
async.each(ids, function (uid, next) {
|
||||||
|
progress.incr();
|
||||||
|
db.getSortedSetRevRange('uid:' + uid + ':moderation:notes', 0, -1, function (err, notes) {
|
||||||
|
if (err || !notes.length) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.eachSeries(notes, function (note, next) {
|
||||||
|
var noteData;
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
try {
|
||||||
|
noteData = JSON.parse(note);
|
||||||
|
setImmediate(next);
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.sortedSetRemove('uid:' + uid + ':moderation:notes', note, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.setObject('uid:' + uid + ':moderation:note:' + noteData.timestamp, {
|
||||||
|
uid: noteData.uid,
|
||||||
|
timestamp: noteData.timestamp,
|
||||||
|
note: noteData.note,
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.sortedSetAdd('uid:' + uid + ':moderation:notes', noteData.timestamp, noteData.timestamp, next);
|
||||||
|
},
|
||||||
|
], next);
|
||||||
|
}, next);
|
||||||
|
});
|
||||||
|
}, next);
|
||||||
|
}, {
|
||||||
|
progress: this.progress,
|
||||||
|
}, callback);
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue