diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 2f09cbe68f..06e7526f89 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -190,7 +190,7 @@ SocketTopics.markAsUnreadForAll = function(socket, tids, callback) { return next(err); } - db.sortedSetAdd('topics:recent', Date.now(), tid, function(err) { + topics.updateRecent(tid, Date.now(), function(err) { if(err) { return next(err); } diff --git a/src/topics.js b/src/topics.js index 99a1c6b761..545945af89 100644 --- a/src/topics.js +++ b/src/topics.js @@ -470,11 +470,6 @@ var async = require('async'), }); }; - Topics.updateTimestamp = function(tid, timestamp) { - db.sortedSetAdd('topics:recent', timestamp, tid); - Topics.setTopicField(tid, 'lastposttime', timestamp); - }; - Topics.getUids = function(tid, callback) { Topics.getPids(tid, function(err, pids) { if (err) { diff --git a/src/topics/delete.js b/src/topics/delete.js index c1966bd7b2..2a654b551c 100644 --- a/src/topics/delete.js +++ b/src/topics/delete.js @@ -41,7 +41,7 @@ module.exports = function(Topics) { Topics.setTopicField(tid, 'deleted', 1, next); }, function(next) { - db.sortedSetRemove('topics:recent', tid, next); + Topics.removeRecent(tid, next); }, function(next) { db.sortedSetRemove('topics:posts', tid, next); @@ -69,7 +69,7 @@ module.exports = function(Topics) { Topics.setTopicField(tid, 'deleted', 0, next); }, function(next) { - db.sortedSetAdd('topics:recent', topicData.lastposttime, tid, next); + Topics.updateRecent(tid, topicData.lastposttime, next); }, function(next) { db.sortedSetAdd('topics:posts', topicData.postcount, tid, next); @@ -99,7 +99,7 @@ module.exports = function(Topics) { db.sortedSetRemove('topics:tid', tid, next); }, function(next) { - db.sortedSetRemove('topics:recent', tid, next); + Topics.removeRecent(tid, next); }, function(next) { db.sortedSetRemove('topics:posts', tid, next); diff --git a/src/topics/recent.js b/src/topics/recent.js index 8a3d8011e8..77d8023d32 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -33,4 +33,17 @@ module.exports = function(Topics) { db.getSortedSetRevRangeByScore('topics:recent', start, count, Infinity, Date.now() - since, callback); }; + Topics.updateTimestamp = function(tid, timestamp) { + Topics.updateRecent(tid, timestamp); + Topics.setTopicField(tid, 'lastposttime', timestamp); + }; + + Topics.updateRecent = function(tid, timestamp, callback) { + callback = callback || function() {}; + db.sortedSetAdd('topics:recent', timestamp, tid, callback); + }; + + Topics.removeRecent = function(tid, callback) { + db.sortedSetRemove('topics:recent', tid, callback); + }; };