mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #12444 add uncategorized topics counted stats to separate sorted set
This commit is contained in:
@@ -50,6 +50,12 @@ module.exports = function (Topics) {
|
||||
`cid:${topicData.cid}:tids:create`,
|
||||
`cid:${topicData.cid}:uid:${topicData.uid}:tids`,
|
||||
];
|
||||
const countedSortedSetKeys = [
|
||||
...['views', 'posts', 'votes'].map(prop => `${topicData.cid === -1 ? 'topicsRemote' : 'topics'}:${prop}`),
|
||||
`cid:${topicData.cid}:tids:votes`,
|
||||
`cid:${topicData.cid}:tids:posts`,
|
||||
`cid:${topicData.cid}:tids:views`,
|
||||
];
|
||||
|
||||
const scheduled = timestamp > Date.now();
|
||||
if (scheduled) {
|
||||
@@ -58,12 +64,7 @@ module.exports = function (Topics) {
|
||||
|
||||
await Promise.all([
|
||||
db.sortedSetsAdd(timestampedSortedSetKeys, timestamp, topicData.tid),
|
||||
db.sortedSetsAdd([
|
||||
'topics:views', 'topics:posts', 'topics:votes',
|
||||
`cid:${topicData.cid}:tids:votes`,
|
||||
`cid:${topicData.cid}:tids:posts`,
|
||||
`cid:${topicData.cid}:tids:views`,
|
||||
], 0, topicData.tid),
|
||||
db.sortedSetsAdd(countedSortedSetKeys, 0, topicData.tid),
|
||||
user.addTopicIdToUser(topicData.uid, topicData.tid, timestamp),
|
||||
db.incrObjectField(`category:${topicData.cid}`, 'topic_count'),
|
||||
db.incrObjectField('global', 'topicCount'),
|
||||
|
||||
36
src/upgrades/4.0.0/fix_topic_zsets_for_uncategorized.js
Normal file
36
src/upgrades/4.0.0/fix_topic_zsets_for_uncategorized.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// REMOVE THIS PRIOR TO 4.0 ALPHA
|
||||
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix topic sorted sets for uncategorized topics',
|
||||
timestamp: Date.UTC(2024, 2, 26),
|
||||
method: async function () {
|
||||
const props = ['views', 'posts', 'votes'];
|
||||
const { progress } = this;
|
||||
const tids = await db.getSortedSetMembers('cid:-1:tids');
|
||||
progress.total = tids.length;
|
||||
|
||||
const remove = [];
|
||||
const add = [];
|
||||
await Promise.all(props.map(async (prop) => {
|
||||
const set = `topics:${prop}`;
|
||||
const newSet = `topicsRemote:${prop}`;
|
||||
|
||||
const scores = await db.sortedSetScores(set, tids);
|
||||
scores.forEach((score, idx) => {
|
||||
if (score !== null) {
|
||||
remove.push([set, tids[idx]]);
|
||||
add.push([newSet, score, tids[idx]]);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
await Promise.all([
|
||||
db.sortedSetRemoveBulk(remove),
|
||||
db.sortedSetAddBulk(add),
|
||||
]);
|
||||
},
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
// REMOVE THIS PRIOR TO 4.0 ALPHA
|
||||
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
|
||||
Reference in New Issue
Block a user