Skip to content

Commit

Permalink
feat: upgrade script for #8510
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jul 17, 2020
1 parent 1e14af4 commit 08c75c0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/upgrades/1.14.3/consolidate_flags.js
Original file line number Diff line number Diff line change
@@ -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,
});
},
};

0 comments on commit 08c75c0

Please sign in to comment.