From 030294a10d69cf1eb8e0916e629a74f958158dd9 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Sat, 12 Aug 2023 03:52:20 -0400 Subject: [PATCH] perf: query home and local --- .../server/api/endpoints/notes/hybrid-timeline.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 9dec9d8c26..03ce0a0401 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -125,7 +125,7 @@ export default define(meta, paramDef, async (ps, user) => { UserBlockedCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), ]); - const validUserIds = [user.id].concat(followingUserIds); + const validUserIds = [user.id, ...followingUserIds]; const optFilter = (n: ScyllaNote) => !n.renoteId || !!n.text || n.files.length > 0 || n.hasPoll; @@ -167,10 +167,13 @@ export default define(meta, paramDef, async (ps, user) => { const foundPacked = []; while (foundPacked.length < ps.limit) { - const foundNotes = (await execNotePaginationQuery("global", ps, filter)).slice( - 0, - ps.limit * 1.5, - ); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. + const [homeFoundNotes, localFoundNotes] = await Promise.all([ + execNotePaginationQuery("home", ps, filter, user.id), + execNotePaginationQuery("local", ps, filter), + ]); + const foundNotes = [...homeFoundNotes, ...localFoundNotes] + .sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()) + .slice(0, ps.limit * 1.5); // Some may be filtered out by Notes.packMany, thus we take more than ps.limit. foundPacked.push( ...(await Notes.packMany(foundNotes, user, { scyllaNote: true })), );