Node.js based forum software built for the modern web
add new zset
Baris Usakli6778cce265b6
diff --git a/src/categories/topics.js b/src/categories/topics.jsindex bc776b01d1..337357290c 100644--- a/src/categories/topics.js+++ b/src/categories/topics.js@@ -216,6 +216,9 @@ module.exports = function (Categories) {function (next) {db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);},+ function (next) {+ db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', postData.timestamp, postData.tid, next);+ },function (next) {db.incrObjectField('category:' + cid, 'post_count', next);},diff --git a/src/topics/delete.js b/src/topics/delete.jsindex a344ee87dd..1c6f261f73 100644--- a/src/topics/delete.js+++ b/src/topics/delete.js@@ -195,6 +195,7 @@ module.exports = function (Topics) {'cid:' + topicData.cid + ':tids','cid:' + topicData.cid + ':tids:pinned','cid:' + topicData.cid + ':tids:posts',+ 'cid:' + topicData.cid + ':tids:lastposttime','cid:' + topicData.cid + ':recent_tids','cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids','uid:' + topicData.uid + ':topics',diff --git a/src/topics/recent.js b/src/topics/recent.jsindex a30c213fdd..2e77262d44 100644--- a/src/topics/recent.js+++ b/src/topics/recent.js@@ -28,7 +28,13 @@ module.exports = function (Topics) {}async.waterfall([function (next) {- db.getSortedSetRevRange('topics:recent', 0, 199, next);+ var key = 'topics:recent';+ if (cid) {+ key = cid.map(function (cid) {+ return 'cid:' + cid + ':tids:lastposttime';+ });+ }+ db.getSortedSetRevRange(key, 0, 199, next);},function (tids, next) {filterTids(tids, uid, filter, cid, next);@@ -119,12 +125,17 @@ module.exports = function (Topics) {Topics.updateTimestamp = function (tid, timestamp, callback) {async.parallel([function (next) {+ var topicData;async.waterfall([function (next) {- Topics.getTopicField(tid, 'deleted', next);+ Topics.getTopicFields(tid, ['cid', 'deleted'], next);+ },+ function (_topicData, next) {+ topicData = _topicData;+ db.sortedSetAdd('cid:' + topicData.cid + ':tids:lastposttime', timestamp, tid, next);},- function (deleted, next) {- if (parseInt(deleted, 10) === 1) {+ function (next) {+ if (parseInt(topicData.deleted, 10) === 1) {return next();}Topics.updateRecent(tid, timestamp, next);diff --git a/src/topics/tools.js b/src/topics/tools.jsindex 743aa9d38d..031c27c287 100644--- a/src/topics/tools.js+++ b/src/topics/tools.js@@ -262,9 +262,13 @@ module.exports = function (Topics) {'cid:' + topicData.cid + ':tids','cid:' + topicData.cid + ':tids:pinned','cid:' + topicData.cid + ':tids:posts',+ 'cid:' + topicData.cid + ':tids:lastposttime','cid:' + topicData.cid + ':recent_tids',], tid, next);},+ function (next) {+ db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next);+ },function (next) {if (parseInt(topic.pinned, 10)) {db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next);diff --git a/src/upgrade.js b/src/upgrade.jsindex 43c012d8c0..7229c87227 100644--- a/src/upgrade.js+++ b/src/upgrade.js@@ -195,8 +195,8 @@ Upgrade.process = function (files, skipCount, callback) {], callback);};-Upgrade.incrementProgress = function () {- this.current += 1;+Upgrade.incrementProgress = function (value) {+ this.current += value || 1;// Redraw the progress barvar percentage = 0;diff --git a/src/upgrades/1.6.2/topics_lastposttime_zset.js b/src/upgrades/1.6.2/topics_lastposttime_zset.jsnew file mode 100644index 0000000000..8e12b1744a--- /dev/null+++ b/src/upgrades/1.6.2/topics_lastposttime_zset.js@@ -0,0 +1,29 @@+'use strict';++var async = require('async');++var db = require('../../database');++module.exports = {+ name: 'New sorted set cid:<cid>:tids:lastposttime',+ timestamp: Date.UTC(2017, 9, 30),+ method: function (callback) {+ var progress = this.progress;++ require('../../batch').processSortedSet('topics:tid', function (tids, next) {+ async.eachSeries(tids, function (tid, next) {+ db.getObjectFields('topic:' + tid, ['cid', 'timestamp', 'lastposttime'], function (err, topicData) {+ if (err || !topicData) {+ return next(err);+ }+ progress.incr();++ var timestamp = topicData.lastposttime || topicData.timestamp || Date.now();+ db.sortedSetAdd('cid:' + topicData.cid + ':tids:lastposttime', timestamp, tid, next);+ }, next);+ }, next);+ }, {+ progress: this.progress,+ }, callback);+ },+};