mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 00:45:47 +01:00
add new zset
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 (deleted, next) {
|
||||
if (parseInt(deleted, 10) === 1) {
|
||||
function (_topicData, next) {
|
||||
topicData = _topicData;
|
||||
db.sortedSetAdd('cid:' + topicData.cid + ':tids:lastposttime', timestamp, tid, next);
|
||||
},
|
||||
function (next) {
|
||||
if (parseInt(topicData.deleted, 10) === 1) {
|
||||
return next();
|
||||
}
|
||||
Topics.updateRecent(tid, timestamp, next);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 bar
|
||||
var percentage = 0;
|
||||
|
||||
29
src/upgrades/1.6.2/topics_lastposttime_zset.js
Normal file
29
src/upgrades/1.6.2/topics_lastposttime_zset.js
Normal file
@@ -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);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user