mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-02 13:50:36 +01:00
feat: upgrade script for #8510
This commit is contained in:
38
src/upgrades/1.14.3/consolidate_flags.js
Normal file
38
src/upgrades/1.14.3/consolidate_flags.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
const posts = require('../../posts');
|
||||
const user = require('../../user');
|
||||
|
||||
module.exports = {
|
||||
name: 'Consolidate multiple flags reports, going forward',
|
||||
timestamp: Date.UTC(2020, 6, 16),
|
||||
method: async function () {
|
||||
const progress = this.progress;
|
||||
|
||||
let flags = await db.getSortedSetRange('flags:datetime', 0, -1);
|
||||
flags = flags.map(flagId => `flag:${flagId}`);
|
||||
flags = await db.getObjectsFields(flags, ['flagId', 'type', 'targetId']);
|
||||
progress.total = flags.length;
|
||||
|
||||
await batch.processArray(flags, async function (subset) {
|
||||
progress.incr(subset.length);
|
||||
|
||||
await Promise.all(subset.map(async (flagObj) => {
|
||||
switch (flagObj.type) {
|
||||
case 'post':
|
||||
await posts.setPostField(flagObj.targetId, 'flagId', flagObj.flagId);
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
await user.setUserField(flagObj.targetId, 'flagId', flagObj.flagId);
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}, {
|
||||
progress: progress,
|
||||
batch: 500,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user