Skip to content

Node.js based forum software built for the modern web

fix: #12919, handle when buildTopicsSortedSet returns a non-array

Julian Lame4e6b1d2458c
diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.js
index 5448263e21..900c87a449 100644
--- a/src/controllers/activitypub/topics.js
+++ b/src/controllers/activitypub/topics.js
@@ -23,8 +23,13 @@ const validSorts = [
async function getTids(data) {
// Poor man's intersect used instead of getSortedSetIntersect because the zsets are huge
const sets = await categories.buildTopicsSortedSet(data);
- const mainSet = sets.shift();
+ const intersect = Array.isArray(sets);
+ const mainSet = intersect ? sets.shift() : sets;
let tids = await db.getSortedSetRevRange(mainSet, 0, 499);
+ if (!intersect) {
+ return tids.slice(data.start, data.stop + 1);
+ }
+
let intersection = await Promise.all(sets.map(async set => db.isSortedSetMembers(set, tids)));
intersection = intersection.reduce((memo, cur) => memo.map((show, idx) => show && cur[idx]));
tids = tids.filter((_, idx) => intersection[idx]);