From e4e6b1d2458c90e0fc4c603d080a2362886e36fc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 18 Nov 2024 13:47:34 -0500 Subject: [PATCH] fix: #12919, handle when buildTopicsSortedSet returns a non-array --- src/controllers/activitypub/topics.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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]);