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,47 +1,38 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const async = require('async');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Widget visibility groups',
|
name: 'Widget visibility groups',
|
||||||
timestamp: Date.UTC(2018, 10, 10),
|
timestamp: Date.UTC(2018, 10, 10),
|
||||||
method: function (callback) {
|
method: async function () {
|
||||||
const widgetAdmin = require('../../widgets/admin');
|
const widgetAdmin = require('../../widgets/admin');
|
||||||
const widgets = require('../../widgets');
|
const widgets = require('../../widgets');
|
||||||
async.waterfall([
|
const areas = await widgetAdmin.getAreas();
|
||||||
function (next) {
|
for (const area of areas) {
|
||||||
widgetAdmin.getAreas(next);
|
if (area.data.length) {
|
||||||
},
|
// area.data is actually an array of widgets
|
||||||
function (areas, next) {
|
area.widgets = area.data;
|
||||||
async.eachSeries(areas, (area, next) => {
|
area.widgets.forEach((widget) => {
|
||||||
if (area.data.length) {
|
if (widget && widget.data) {
|
||||||
// area.data is actually an array of widgets
|
const groupsToShow = ['administrators', 'Global Moderators'];
|
||||||
area.widgets = area.data;
|
if (widget.data['hide-guests'] !== 'on') {
|
||||||
area.widgets.forEach((widget) => {
|
groupsToShow.push('guests');
|
||||||
if (widget && widget.data) {
|
}
|
||||||
const groupsToShow = ['administrators', 'Global Moderators'];
|
if (widget.data['hide-registered'] !== 'on') {
|
||||||
if (widget.data['hide-guests'] !== 'on') {
|
groupsToShow.push('registered-users');
|
||||||
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
|
// if we are showing to all 4 groups, set to empty array
|
||||||
// empty groups is shown to everyone
|
// empty groups is shown to everyone
|
||||||
if (groupsToShow.length === 4) {
|
if (groupsToShow.length === 4) {
|
||||||
widget.data.groups.length = 0;
|
widget.data.groups.length = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
widgets.setArea(area, next);
|
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
}, next);
|
});
|
||||||
},
|
// eslint-disable-next-line no-await-in-loop
|
||||||
], callback);
|
await widgets.setArea(area);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -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) {
|
noteData.timestamp = noteData.timestamp || Date.now();
|
||||||
try {
|
await db.sortedSetRemove(`uid:${uid}:moderation:notes`, note);
|
||||||
noteData = JSON.parse(note);
|
await db.setObject(`uid:${uid}:moderation:note:${noteData.timestamp}`, {
|
||||||
noteData.timestamp = noteData.timestamp || Date.now();
|
uid: noteData.uid,
|
||||||
setImmediate(next);
|
timestamp: noteData.timestamp,
|
||||||
} catch (err) {
|
note: noteData.note,
|
||||||
next(err);
|
});
|
||||||
}
|
await db.sortedSetAdd(`uid:${uid}:moderation:notes`, noteData.timestamp, noteData.timestamp);
|
||||||
},
|
}
|
||||||
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,
|
progress: this.progress,
|
||||||
}, callback);
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue