change the way group member posts are stored

This commit is contained in:
Barış Soner Uşaklı
2017-05-04 16:32:51 -04:00
parent 670a5d9ca0
commit 14f3907aa4
6 changed files with 100 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ var _ = require('underscore');
var db = require('../database');
var topics = require('../topics');
var user = require('../user');
var groups = require('../groups');
var notifications = require('../notifications');
var plugins = require('../plugins');
@@ -141,6 +142,9 @@ module.exports = function (Posts) {
function (next) {
deletePostFromReplies(pid, next);
},
function (next) {
deletePostFromGroups(pid, next);
},
function (next) {
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
},
@@ -294,4 +298,27 @@ module.exports = function (Posts) {
], callback);
});
}
function deletePostFromGroups(pid, callback) {
async.waterfall([
function (next) {
Posts.getPostField(pid, 'uid', next);
},
function (uid, next) {
if (!parseInt(uid, 10)) {
return callback();
}
groups.getUserGroupMembership('groups:visible:createtime', [uid], next);
},
function (groupNames, next) {
groupNames = groupNames[0];
var keys = groupNames.map(function (groupName) {
return 'group:' + groupName + ':member:pids';
});
db.sortedSetsRemove(keys, pid, next);
},
], callback);
}
};