refactor: remove async.waterfall
parent
222dccaf67
commit
58ac55c16a
@ -1,24 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const async = require('async');
|
|
||||||
const db = require('../../database');
|
const db = require('../../database');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Rename maximumImageWidth to resizeImageWidth',
|
name: 'Rename maximumImageWidth to resizeImageWidth',
|
||||||
timestamp: Date.UTC(2018, 9, 24),
|
timestamp: Date.UTC(2018, 9, 24),
|
||||||
method: function (callback) {
|
method: async function () {
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
async.waterfall([
|
const value = await meta.configs.get('maximumImageWidth');
|
||||||
function (next) {
|
await meta.configs.set('resizeImageWidth', value);
|
||||||
meta.configs.get('maximumImageWidth', next);
|
await db.deleteObjectField('config', 'maximumImageWidth');
|
||||||
},
|
|
||||||
function (value, next) {
|
|
||||||
meta.configs.set('resizeImageWidth', value, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
db.deleteObjectField('config', 'maximumImageWidth', next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,55 +1,35 @@
|
|||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const async = require('async');
|
|
||||||
const db = require('../../database');
|
const db = require('../../database');
|
||||||
const batch = require('../../batch');
|
const batch = require('../../batch');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Update moderation notes to hashes',
|
name: 'Update moderation notes to hashes',
|
||||||
timestamp: Date.UTC(2019, 3, 5),
|
timestamp: Date.UTC(2019, 3, 5),
|
||||||
method: function (callback) {
|
method: async function () {
|
||||||
const { progress } = this;
|
const { progress } = this;
|
||||||
|
|
||||||
batch.processSortedSet('users:joindate', (ids, next) => {
|
await batch.processSortedSet('users:joindate', async (uids) => {
|
||||||
async.each(ids, (uid, next) => {
|
await Promise.all(uids.map(async (uid) => {
|
||||||
progress.incr();
|
progress.incr();
|
||||||
db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, 0, -1, (err, notes) => {
|
|
||||||
if (err || !notes.length) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.eachSeries(notes, (note, next) => {
|
const notes = await db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, 0, -1);
|
||||||
let noteData;
|
for (const note of notes) {
|
||||||
async.waterfall([
|
const noteData = JSON.parse(note);
|
||||||
function (next) {
|
|
||||||
try {
|
|
||||||
noteData = JSON.parse(note);
|
|
||||||
noteData.timestamp = noteData.timestamp || Date.now();
|
noteData.timestamp = noteData.timestamp || Date.now();
|
||||||
setImmediate(next);
|
await db.sortedSetRemove(`uid:${uid}:moderation:notes`, note);
|
||||||
} catch (err) {
|
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, {
|
||||||
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,
|
uid: noteData.uid,
|
||||||
timestamp: noteData.timestamp,
|
timestamp: noteData.timestamp,
|
||||||
note: noteData.note,
|
note: noteData.note,
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp, next);
|
|
||||||
},
|
|
||||||
], next);
|
|
||||||
}, next);
|
|
||||||
});
|
});
|
||||||
}, next);
|
await db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}, {
|
}, {
|
||||||
progress: this.progress,
|
progress: this.progress,
|
||||||
}, callback);
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue