You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/upgrades/1.1.0/dismiss_flags_from_deleted_...

44 lines
1.0 KiB
JavaScript

/* jslint node: true */
'use strict';
var db = require('../../database');
var async = require('async');
var winston = require('winston');
module.exports = {
name: 'Dismiss flags from deleted topics',
timestamp: Date.UTC(2016, 3, 29),
method: function (callback) {
var posts = require('../../posts');
var topics = require('../../topics');
var pids;
var tids;
async.waterfall([
async.apply(db.getSortedSetRange, 'posts:flagged', 0, -1),
function (_pids, next) {
pids = _pids;
posts.getPostsFields(pids, ['tid'], next);
},
function (_tids, next) {
tids = _tids.map(function (a) {
return a.tid;
});
topics.getTopicsFields(tids, ['deleted'], next);
},
function (state, next) {
var toDismiss = state.map(function (a, idx) {
return parseInt(a.deleted, 10) === 1 ? pids[idx] : null;
}).filter(Boolean);
winston.verbose('[2016/04/29] ' + toDismiss.length + ' dismissable flags found');
async.each(toDismiss, posts.dismissFlag, next);
},
], callback);
},
};