mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
perf: ~18x speedup of /world route
- upgrade script to remove pruned tids that did not get removed from inbox - switch from db intersect to manual intersection of subset.
This commit is contained in:
@@ -46,13 +46,11 @@ controller.list = async function (req, res) {
|
||||
]);
|
||||
const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;
|
||||
|
||||
const sets = [sortToSet[sort], `uid:${req.uid}:inbox`];
|
||||
const tids = await db.getSortedSetRevIntersect({
|
||||
sets,
|
||||
start,
|
||||
stop,
|
||||
weights: sets.map((s, index) => (index ? 0 : 1)),
|
||||
});
|
||||
let tids = await db.getSortedSetRevRange(sortToSet[sort], 0, 499);
|
||||
const isMembers = await db.isSortedSetMembers(`uid:${req.uid}:inbox`, tids);
|
||||
tids = tids.filter((tid, idx) => isMembers[idx]);
|
||||
const count = tids.length;
|
||||
tids = tids.slice(start, stop);
|
||||
|
||||
const targetUid = await user.getUidByUserslug(req.query.author);
|
||||
|
||||
@@ -71,7 +69,7 @@ controller.list = async function (req, res) {
|
||||
data.name = '[[activitypub:world.name]]';
|
||||
delete data.children;
|
||||
|
||||
data.topicCount = await db.sortedSetIntersectCard(sets);
|
||||
data.topicCount = count;
|
||||
data.topics = await topics.getTopicsByTids(tids, { uid: req.uid });
|
||||
topics.calculateTopicIndices(data.topics, start);
|
||||
|
||||
|
||||
29
src/upgrades/4.0.0/prune_user_inboxes.js
Normal file
29
src/upgrades/4.0.0/prune_user_inboxes.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const db = require('../../database');
|
||||
const batch = require('../../batch');
|
||||
const topics = require('../../topics');
|
||||
|
||||
module.exports = {
|
||||
name: 'Prune deleted topics out of user inboxes',
|
||||
timestamp: Date.UTC(2024, 6, 12),
|
||||
method: async function () {
|
||||
const { progress } = this;
|
||||
|
||||
await batch.processSortedSet('users:joindate', async (uids) => {
|
||||
const exists = await db.exists(uids.map(uid => `uid:${uid}:inbox`));
|
||||
const count = uids.length;
|
||||
uids = uids.filter((uid, idx) => exists[idx]);
|
||||
|
||||
await Promise.all(uids.map(async (uid) => {
|
||||
const key = `uid:${uid}:inbox`;
|
||||
const tids = await db.getSortedSetMembers(key);
|
||||
const exists = await topics.exists(tids);
|
||||
const toRemove = tids.filter((tid, idx) => !exists[idx]);
|
||||
await db.sortedSetRemove(key, toRemove);
|
||||
}));
|
||||
|
||||
progress.incr(count);
|
||||
}, { progress });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user