mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
closes #4583
This commit is contained in:
@@ -81,6 +81,21 @@ var plugins = require('./plugins');
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.filterExists = function(nids, callback) {
|
||||
// Removes nids that have been pruned
|
||||
db.isSortedSetMembers('notifications', nids, function(err, exists) {
|
||||
if (err) {
|
||||
return callbacK(err);
|
||||
}
|
||||
|
||||
nids = nids.filter(function(notifId, idx) {
|
||||
return exists[idx];
|
||||
});
|
||||
|
||||
callback(null, nids);
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.findRelated = function(mergeIds, set, callback) {
|
||||
// A related notification is one in a zset that has the same mergeId
|
||||
var _nids;
|
||||
|
||||
@@ -67,13 +67,17 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
Posts.dismissFlag = function(pid, callback) {
|
||||
var uid;
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.getObjectField('post:' + pid, 'uid', function(err, uid) {
|
||||
db.getObjectField('post:' + pid, 'uid', function(err, _uid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
uid = _uid;
|
||||
|
||||
db.sortedSetsRemove([
|
||||
'posts:flagged',
|
||||
'posts:flags:count',
|
||||
@@ -81,15 +85,10 @@ module.exports = function(Posts) {
|
||||
], pid, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
db.deleteObjectField('post:' + pid, 'flags', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('pid:' + pid + ':flag:uids', next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('pid:' + pid + ':flag:uid:reason', next);
|
||||
}
|
||||
async.apply(db.deleteObjectField, 'post:' + pid, 'flags'),
|
||||
async.apply(db.delete, 'pid:' + pid + ':flag:uids'),
|
||||
async.apply(db.delete, 'pid:' + pid + ':flag:uid:reason'),
|
||||
async.apply(db.sortedSetRemove, 'notifications', 'post_flag:' + pid + ':uid:' + uid)
|
||||
], function(err) {
|
||||
callback(err);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2016, 3, 18);
|
||||
latestSchema = Date.UTC(2016, 3, 29);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -530,6 +530,52 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2016/04/19] Users post count per tid skipped!');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2016, 3, 29);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2016/04/29] Dismiss flags from deleted topics');
|
||||
|
||||
var posts = require('./posts'),
|
||||
topics = require('./topics');
|
||||
|
||||
var pids, 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.info('[2016/04/29] ' + toDismiss.length + ' dismissable flags found');
|
||||
async.each(toDismiss, posts.dismissFlag, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2016/04/29] Dismiss flags from deleted topics done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2016/04/29] Dismiss flags from deleted topics skipped!');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||
|
||||
@@ -211,6 +211,7 @@ var async = require('async'),
|
||||
// Collapse any notifications with identical mergeIds
|
||||
async.waterfall([
|
||||
async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':notifications:unread', 0, 99),
|
||||
async.apply(notifications.filterExists),
|
||||
function(nids, next) {
|
||||
var keys = nids.map(function(nid) {
|
||||
return 'notifications:' + nid;
|
||||
|
||||
Reference in New Issue
Block a user