refactor: remove async.waterfall
parent
222dccaf67
commit
58ac55c16a
@ -1,24 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const db = require('../../database');
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'Rename maximumImageWidth to resizeImageWidth',
|
||||
timestamp: Date.UTC(2018, 9, 24),
|
||||
method: function (callback) {
|
||||
method: async function () {
|
||||
const meta = require('../../meta');
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
meta.configs.get('maximumImageWidth', next);
|
||||
},
|
||||
function (value, next) {
|
||||
meta.configs.set('resizeImageWidth', value, next);
|
||||
},
|
||||
function (next) {
|
||||
db.deleteObjectField('config', 'maximumImageWidth', next);
|
||||
},
|
||||
], callback);
|
||||
const value = await meta.configs.get('maximumImageWidth');
|
||||
await meta.configs.set('resizeImageWidth', value);
|
||||
await db.deleteObjectField('config', 'maximumImageWidth');
|
||||
},
|
||||
};
|
||||
|
@ -1,47 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
|
||||
module.exports = {
|
||||
name: 'Widget visibility groups',
|
||||
timestamp: Date.UTC(2018, 10, 10),
|
||||
method: function (callback) {
|
||||
method: async function () {
|
||||
const widgetAdmin = require('../../widgets/admin');
|
||||
const widgets = require('../../widgets');
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
widgetAdmin.getAreas(next);
|
||||
},
|
||||
function (areas, next) {
|
||||
async.eachSeries(areas, (area, next) => {
|
||||
if (area.data.length) {
|
||||
// area.data is actually an array of widgets
|
||||
area.widgets = area.data;
|
||||
area.widgets.forEach((widget) => {
|
||||
if (widget && widget.data) {
|
||||
const groupsToShow = ['administrators', 'Global Moderators'];
|
||||
if (widget.data['hide-guests'] !== 'on') {
|
||||
groupsToShow.push('guests');
|
||||
}
|
||||
if (widget.data['hide-registered'] !== 'on') {
|
||||
groupsToShow.push('registered-users');
|
||||
}
|
||||
const areas = await widgetAdmin.getAreas();
|
||||
for (const area of areas) {
|
||||
if (area.data.length) {
|
||||
// area.data is actually an array of widgets
|
||||
area.widgets = area.data;
|
||||
area.widgets.forEach((widget) => {
|
||||
if (widget && widget.data) {
|
||||
const groupsToShow = ['administrators', 'Global Moderators'];
|
||||
if (widget.data['hide-guests'] !== 'on') {
|
||||
groupsToShow.push('guests');
|
||||
}
|
||||
if (widget.data['hide-registered'] !== 'on') {
|
||||
groupsToShow.push('registered-users');
|
||||
}
|
||||
|
||||
widget.data.groups = groupsToShow;
|
||||
widget.data.groups = groupsToShow;
|
||||
|
||||
// if we are showing to all 4 groups, set to empty array
|
||||
// empty groups is shown to everyone
|
||||
if (groupsToShow.length === 4) {
|
||||
widget.data.groups.length = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
widgets.setArea(area, next);
|
||||
} else {
|
||||
next();
|
||||
// if we are showing to all 4 groups, set to empty array
|
||||
// empty groups is shown to everyone
|
||||
if (groupsToShow.length === 4) {
|
||||
widget.data.groups.length = 0;
|
||||
}
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await widgets.setArea(area);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,55 +1,35 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'Update moderation notes to hashes',
|
||||
timestamp: Date.UTC(2019, 3, 5),
|
||||
method: function (callback) {
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
|
||||
batch.processSortedSet('users:joindate', (ids, next) => {
|
||||
async.each(ids, (uid, next) => {
|
||||
await batch.processSortedSet('users:joindate', async (uids) => {
|
||||
await Promise.all(uids.map(async (uid) => {
|
||||
progress.incr();
|
||||
db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, 0, -1, (err, notes) => {
|
||||
if (err || !notes.length) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.eachSeries(notes, (note, next) => {
|
||||
let noteData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
try {
|
||||
noteData = JSON.parse(note);
|
||||
noteData.timestamp = noteData.timestamp || Date.now();
|
||||
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);
|
||||
const notes = await db.getSortedSetRevRange(`uid:${uid}:moderation:notes`, 0, -1);
|
||||
for (const note of notes) {
|
||||
const noteData = JSON.parse(note);
|
||||
noteData.timestamp = noteData.timestamp || Date.now();
|
||||
await db.sortedSetRemove(`uid:${uid}:moderation:notes`, note);
|
||||
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, {
|
||||
uid: noteData.uid,
|
||||
timestamp: noteData.timestamp,
|
||||
note: noteData.note,
|
||||
});
|
||||
await db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp);
|
||||
}
|
||||
}));
|
||||
}, {
|
||||
progress: this.progress,
|
||||
}, callback);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue