mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +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) {
|
Notifications.findRelated = function(mergeIds, set, callback) {
|
||||||
// A related notification is one in a zset that has the same mergeId
|
// A related notification is one in a zset that has the same mergeId
|
||||||
var _nids;
|
var _nids;
|
||||||
|
|||||||
@@ -67,13 +67,17 @@ module.exports = function(Posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Posts.dismissFlag = function(pid, callback) {
|
Posts.dismissFlag = function(pid, callback) {
|
||||||
|
var uid;
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
db.getObjectField('post:' + pid, 'uid', function(err, uid) {
|
db.getObjectField('post:' + pid, 'uid', function(err, _uid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid = _uid;
|
||||||
|
|
||||||
db.sortedSetsRemove([
|
db.sortedSetsRemove([
|
||||||
'posts:flagged',
|
'posts:flagged',
|
||||||
'posts:flags:count',
|
'posts:flags:count',
|
||||||
@@ -81,15 +85,10 @@ module.exports = function(Posts) {
|
|||||||
], pid, next);
|
], pid, next);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
async.apply(db.deleteObjectField, 'post:' + pid, 'flags'),
|
||||||
db.deleteObjectField('post:' + pid, 'flags', next);
|
async.apply(db.delete, 'pid:' + pid + ':flag:uids'),
|
||||||
},
|
async.apply(db.delete, 'pid:' + pid + ':flag:uid:reason'),
|
||||||
function(next) {
|
async.apply(db.sortedSetRemove, 'notifications', 'post_flag:' + pid + ':uid:' + uid)
|
||||||
db.delete('pid:' + pid + ':flag:uids', next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.delete('pid:' + pid + ':flag:uid:reason', next);
|
|
||||||
}
|
|
||||||
], function(err) {
|
], function(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var db = require('./database'),
|
|||||||
schemaDate, thisSchemaDate,
|
schemaDate, thisSchemaDate,
|
||||||
|
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
latestSchema = Date.UTC(2016, 3, 18);
|
latestSchema = Date.UTC(2016, 3, 29);
|
||||||
|
|
||||||
Upgrade.check = function(callback) {
|
Upgrade.check = function(callback) {
|
||||||
db.get('schemaDate', function(err, value) {
|
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!');
|
winston.info('[2016/04/19] Users post count per tid skipped!');
|
||||||
next();
|
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
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ var async = require('async'),
|
|||||||
// Collapse any notifications with identical mergeIds
|
// Collapse any notifications with identical mergeIds
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':notifications:unread', 0, 99),
|
async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':notifications:unread', 0, 99),
|
||||||
|
async.apply(notifications.filterExists),
|
||||||
function(nids, next) {
|
function(nids, next) {
|
||||||
var keys = nids.map(function(nid) {
|
var keys = nids.map(function(nid) {
|
||||||
return 'notifications:' + nid;
|
return 'notifications:' + nid;
|
||||||
|
|||||||
Reference in New Issue
Block a user