mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
closes #2356
This commit is contained in:
@@ -114,7 +114,7 @@ var db = require('./database'),
|
||||
var tids;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tid' : 'categories:' + data.cid + ':tid', data.start, data.stop, next);
|
||||
Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next);
|
||||
},
|
||||
function(topicIds, next) {
|
||||
tids = topicIds;
|
||||
@@ -169,7 +169,7 @@ var db = require('./database'),
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetRevRank('categories:' + cid + ':tid', tid, callback);
|
||||
db.sortedSetRevRank('cid:' + cid + ':tids', tid, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -467,7 +467,7 @@ var db = require('./database'),
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next);
|
||||
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.incrObjectField('category:' + cid, 'post_count', next);
|
||||
@@ -476,7 +476,7 @@ var db = require('./database'),
|
||||
if (parseInt(topicData.pinned, 10) === 1) {
|
||||
next();
|
||||
} else {
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid, next);
|
||||
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next);
|
||||
}
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -8,7 +8,7 @@ module.exports = function(Categories) {
|
||||
Categories.getActiveUsers = function(cid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 24, next);
|
||||
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 24, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
var keys = pids.map(function(pid) {
|
||||
|
||||
@@ -9,7 +9,7 @@ var async = require('async'),
|
||||
module.exports = function(Categories) {
|
||||
|
||||
Categories.purge = function(cid, callback) {
|
||||
batch.processSortedSet('categories:' + cid + ':tid', function(tids, next) {
|
||||
batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) {
|
||||
async.eachLimit(tids, 10, function(tid, next) {
|
||||
threadTools.purge(tid, 0, next);
|
||||
}, next);
|
||||
@@ -27,7 +27,11 @@ module.exports = function(Categories) {
|
||||
db.sortedSetRemove('categories:cid', cid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.deleteAll(['categories:' + cid + ':tid', 'categories:recent_posts:cid:' + cid, 'category:' + cid], next);
|
||||
db.deleteAll([
|
||||
'cid:' + cid + ':tids',
|
||||
'cid:' + cid + ':pids',
|
||||
'category:' + cid
|
||||
], next);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = function(Categories) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
|
||||
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) {
|
||||
if (err || !pids || !pids.length) {
|
||||
return callback(err, []);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ module.exports = function(Categories) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + category.cid, 0, 0, function(err, pids) {
|
||||
db.getSortedSetRevRange('cid:' + category.cid + ':pids', 0, 0, function(err, pids) {
|
||||
if (err || !Array.isArray(pids) || !pids.length) {
|
||||
return callback(err, []);
|
||||
}
|
||||
@@ -75,10 +75,10 @@ module.exports = function(Categories) {
|
||||
|
||||
async.parallel({
|
||||
pinnedTids: function(next) {
|
||||
db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, -1, Infinity, Date.now(), next);
|
||||
db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, -1, Infinity, Date.now(), next);
|
||||
},
|
||||
tids: function(next) {
|
||||
db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, Math.max(0, count), Date.now(), 0, next);
|
||||
db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, Math.max(0, count), Date.now(), 0, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
@@ -140,10 +140,10 @@ module.exports = function(Categories) {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, movePids, next);
|
||||
db.sortedSetRemove('cid:' + oldCid + ':pids', movePids, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, movePids, next);
|
||||
db.sortedSetAdd('cid:' + cid + ':pids', timestamps, movePids, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
|
||||
@@ -87,7 +87,7 @@ module.exports = function(Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, callback);
|
||||
db.sortedSetRemove('cid:' + cid + ':pids', pid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ module.exports = function(Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid, callback);
|
||||
db.sortedSetAdd('cid:' + cid + ':pids', timestamp, pid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
var sets = cids.map(function(cid) {
|
||||
return 'categories:recent_posts:cid:' + cid;
|
||||
return 'cid:' + cid + ':pids';
|
||||
});
|
||||
|
||||
db.sortedSetsRemove(sets, pid, callback);
|
||||
|
||||
@@ -383,7 +383,7 @@ SocketTopics.moveAll = function(socket, data, callback) {
|
||||
return callback(err || new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
categories.getTopicIds('categories:' + data.currentCid + ':tid', 0, -1, function(err, tids) {
|
||||
categories.getTopicIds('cid:' + data.currentCid + ':tids', 0, -1, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ var winston = require('winston'),
|
||||
|
||||
topics.setTopicField(tid, 'pinned', pin ? 1 : 0);
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||
db.sortedSetAdd('categories:' + topicData.cid + ':tid', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);
|
||||
db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);
|
||||
});
|
||||
|
||||
plugins.fireHook('action:topic.pin', {
|
||||
@@ -192,11 +192,11 @@ var winston = require('winston'),
|
||||
},
|
||||
function(topicData, next) {
|
||||
topic = topicData;
|
||||
db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, next);
|
||||
db.sortedSetRemove('cid:' + topicData.cid + ':tids', tid, next);
|
||||
},
|
||||
function(next) {
|
||||
var timestamp = parseInt(topic.pinned, 10) ? Math.pow(2, 53) : topic.lastposttime;
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid, next);
|
||||
db.sortedSetAdd('cid:' + cid + ':tids', timestamp, tid, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
|
||||
@@ -62,7 +62,11 @@ module.exports = function(Topics) {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.sortedSetsAdd(['topics:tid', 'categories:' + cid + ':tid', 'cid:' + cid + ':uid:' + uid + ':tid'], timestamp, tid, next);
|
||||
db.sortedSetsAdd([
|
||||
'topics:tid',
|
||||
'cid:' + cid + ':tids',
|
||||
'cid:' + cid + ':uid:' + uid + ':tids'
|
||||
], timestamp, tid, next);
|
||||
},
|
||||
function(next) {
|
||||
user.addTopicIdToUser(uid, tid, timestamp, next);
|
||||
|
||||
@@ -77,7 +77,11 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetsRemove(['categories:' + topicData.cid + ':tid', 'uid:' + topicData.uid + ':topics'], tid, callback);
|
||||
db.sortedSetsRemove([
|
||||
'cid:' + topicData.cid + ':tids',
|
||||
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
|
||||
'uid:' + topicData.uid + ':topics'
|
||||
], tid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2014, 10, 6, 18, 30);
|
||||
latestSchema = Date.UTC(2014, 10, 7);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -1170,7 +1170,7 @@ Upgrade.upgrade = function(callback) {
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2014, 10, 6, 18, 30);
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
winston.info('[2014/10/31] Updating topic authorship sorted set');
|
||||
winston.info('[2014/11/6] Updating topic authorship sorted set');
|
||||
|
||||
async.waterfall([
|
||||
async.apply(db.getObjectField, 'global', 'nextTid'),
|
||||
@@ -1201,18 +1201,79 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('[2014/10/31] Error encountered while Updating topic authorship sorted set');
|
||||
winston.error('[2014/11/6] Error encountered while Updating topic authorship sorted set');
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2014/10/31] Updating topic authorship sorted set done');
|
||||
winston.info('[2014/11/6] Updating topic authorship sorted set done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/10/31] Updating topic authorship sorted set skipped');
|
||||
winston.info('[2014/11/6] Updating topic authorship sorted set skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2014, 10, 7);
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
winston.info('[2014/11/7] Renaming sorted set names');
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
cids: function(next) {
|
||||
db.getSortedSetRange('categories:cid', 0, -1, next);
|
||||
},
|
||||
uids: function(next) {
|
||||
db.getSortedSetRange('users:joindate', 0, -1, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
async.eachLimit(results.cids, 50, function(cid, next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.exists('categories:' + cid + ':tid', function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return next(err);
|
||||
}
|
||||
db.rename('categories:' + cid + ':tid', 'cid:' + cid + ':tids', next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
db.exists('categories:recent_posts:cid:' + cid, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return next(err);
|
||||
}
|
||||
db.rename('categories:recent_posts:cid:' + cid, 'cid:' + cid + ':pids', next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
async.eachLimit(results.uids, 50, function(uid, next) {
|
||||
db.exists('cid:' + cid + ':uid:' + uid + ':tid', function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return next(err);
|
||||
}
|
||||
db.rename('cid:' + cid + ':uid:' + uid + ':tid', 'cid:' + cid + ':uid:' + uid + ':tids', next);
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], next);
|
||||
}, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('[2014/11/7] Error encountered while renaming sorted sets');
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2014/11/7] Renaming sorted sets done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/11/7] Renaming sorted sets skipped');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Meta.configs.setOnEmpty = function (field, value, callback) {
|
||||
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
|
||||
], function(err) {
|
||||
|
||||
Reference in New Issue
Block a user