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 sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;
|
||||||
|
|
||||||
const sets = [sortToSet[sort], `uid:${req.uid}:inbox`];
|
let tids = await db.getSortedSetRevRange(sortToSet[sort], 0, 499);
|
||||||
const tids = await db.getSortedSetRevIntersect({
|
const isMembers = await db.isSortedSetMembers(`uid:${req.uid}:inbox`, tids);
|
||||||
sets,
|
tids = tids.filter((tid, idx) => isMembers[idx]);
|
||||||
start,
|
const count = tids.length;
|
||||||
stop,
|
tids = tids.slice(start, stop);
|
||||||
weights: sets.map((s, index) => (index ? 0 : 1)),
|
|
||||||
});
|
|
||||||
|
|
||||||
const targetUid = await user.getUidByUserslug(req.query.author);
|
const targetUid = await user.getUidByUserslug(req.query.author);
|
||||||
|
|
||||||
@@ -71,7 +69,7 @@ controller.list = async function (req, res) {
|
|||||||
data.name = '[[activitypub:world.name]]';
|
data.name = '[[activitypub:world.name]]';
|
||||||
delete data.children;
|
delete data.children;
|
||||||
|
|
||||||
data.topicCount = await db.sortedSetIntersectCard(sets);
|
data.topicCount = count;
|
||||||
data.topics = await topics.getTopicsByTids(tids, { uid: req.uid });
|
data.topics = await topics.getTopicsByTids(tids, { uid: req.uid });
|
||||||
topics.calculateTopicIndices(data.topics, start);
|
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