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

This commit is contained in:
Julian Lam
2024-11-18 13:47:34 -05:00
parent e8fda4c01a
commit e4e6b1d245

View File

@@ -23,8 +23,13 @@ const validSorts = [
async function getTids(data) { async function getTids(data) {
// Poor man's intersect used instead of getSortedSetIntersect because the zsets are huge // Poor man's intersect used instead of getSortedSetIntersect because the zsets are huge
const sets = await categories.buildTopicsSortedSet(data); 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); 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))); 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])); intersection = intersection.reduce((memo, cur) => memo.map((show, idx) => show && cur[idx]));
tids = tids.filter((_, idx) => intersection[idx]); tids = tids.filter((_, idx) => intersection[idx]);