From 8feac114c37b29d6fc224d3db95e090dc73bd08f Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 24 Feb 2014 16:23:11 -0500 Subject: [PATCH] closes #1022 --- src/threadTools.js | 10 +++------- src/topics.js | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/threadTools.js b/src/threadTools.js index b9fde04bc5..66269a9133 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -65,8 +65,6 @@ var winston = require('winston'), return callback(err); } - db.decrObjectField('global', 'topicCount'); - ThreadTools.lock(tid); Plugins.fireHook('action:topic.delete', tid); @@ -101,10 +99,10 @@ var winston = require('winston'), return callback(err); } - db.incrObjectField('global', 'topicCount'); - ThreadTools.unlock(tid); + Plugins.fireHook('action:topic.restore', tid); + events.logTopicRestore(uid, tid); websockets.emitTopicPostStats(); @@ -113,8 +111,6 @@ var winston = require('winston'), tid: tid }); - Plugins.fireHook('action:topic.restore', tid); - callback(null, { tid:tid }); @@ -134,7 +130,7 @@ var winston = require('winston'), tid: tid }); } - } + }; ThreadTools.unlock = function(tid, uid, callback) { topics.setTopicField(tid, 'locked', 0); diff --git a/src/topics.js b/src/topics.js index ca7c134831..5c2690c10a 100644 --- a/src/topics.js +++ b/src/topics.js @@ -1154,6 +1154,16 @@ var async = require('async'), }); } + Topics.updateTopicCount = function(callback) { + db.sortedSetCard('topics:recent', function(err, count) { + if(err) { + return callback(err); + } + + db.setObjectField('global', count, callback); + }); + }; + Topics.delete = function(tid, callback) { async.parallel([ function(next) { @@ -1176,7 +1186,13 @@ var async = require('async'), db.incrObjectFieldBy('category:' + cid, 'topic_count', -1, next); }); } - ], callback); + ], function(err) { + if (err) { + return callback(err); + } + + Topics.updateTopicCount(callback); + }); }; Topics.restore = function(tid, callback) { @@ -1206,7 +1222,13 @@ var async = require('async'), db.incrObjectFieldBy('category:' + cid, 'topic_count', 1, next); }); } - ], callback); + ], function(err) { + if (err) { + return callback(err); + } + + Topics.updateTopicCount(callback); + }); }); }; }(exports));