mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-08 16:42:48 +01:00
Merge pull request #1712 from char101/PR/update-global-counters-on-topic-delete-v2
Update global counters when deleting/restoring topic
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
var async = require('async'),
|
||||
db = require('../database'),
|
||||
|
||||
topics = require('../topics'),
|
||||
plugins = require('../plugins');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
|
||||
Posts.purge = function(pid, callback) {
|
||||
@@ -56,11 +55,17 @@ module.exports = function(Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (parseInt(postData.deleted, 10) === 0) {
|
||||
db.decrObjectField('global', 'postCount', callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
topics.getTopicFields(postData.tid, ['deleted'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (parseInt(postData.deleted, 10) === 0 && parseInt(topicData.deleted, 10) !== 1) {
|
||||
db.decrObjectField('global', 'postCount', callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -124,4 +129,4 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -8,6 +8,23 @@ var async = require('async'),
|
||||
|
||||
module.exports = function(Topics) {
|
||||
|
||||
function updateGlobalCounters(tid, incr, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.incrObjectFieldBy('global', 'topicCount', incr, next);
|
||||
},
|
||||
function(next) {
|
||||
Topics.getPostCount(tid, function(err, postCount) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
postCount = parseInt(postCount, 10) + 1;
|
||||
db.incrObjectFieldBy('global', 'postCount', incr * postCount, next);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
Topics.delete = function(tid, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
@@ -35,7 +52,7 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Topics.updateTopicCount(callback);
|
||||
updateGlobalCounters(tid, -1, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -71,7 +88,7 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Topics.updateTopicCount(callback);
|
||||
updateGlobalCounters(tid, 1, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -135,7 +152,7 @@ module.exports = function(Topics) {
|
||||
db.decrObjectField('category:' + topicData.cid, 'topic_count', next);
|
||||
},
|
||||
function(next) {
|
||||
db.decrObjectField('global', 'topicCount', callback);
|
||||
db.decrObjectField('global', 'topicCount', next);
|
||||
}
|
||||
], callback);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user