From 17161c9ba20dddfccbd730696f4540ef8525912f Mon Sep 17 00:00:00 2001 From: Namekuji Date: Mon, 7 Aug 2023 07:02:51 -0400 Subject: [PATCH] refactor: promise at once --- .../server/api/endpoints/notes/timeline.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index 08548cea40..8a201a8075 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -91,12 +91,20 @@ export default define(meta, paramDef, async (ps, user) => { }); if (scyllaClient) { - const channelCache = await ChannelFollowingsCache.init(user.id); - const followingChannelIds = await channelCache.getAll(); - const followingUserIds = await followingsCache.getAll(); + const [ + followingChannelIds, + followingUserIds, + mutedUserIds, + blockerIds, + renoteMutedIds, + ] = await Promise.all([ + ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), + followingsCache.getAll(), + UserMutingsCache.init(user.id).then((cache) => cache.getAll()), + UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), + ]); const validUserIds = [user.id].concat(followingUserIds); - const userMutingsCache = await UserMutingsCache.init(user.id); - const mutedUserIds = await userMutingsCache.getAll(); const mutedWords = (await userWordMuteCache.fetchMaybe(user.id, () => UserProfiles.findOne({ @@ -104,10 +112,6 @@ export default define(meta, paramDef, async (ps, user) => { where: { userId: user.id }, }).then((profile) => profile?.mutedWords), )) ?? []; - const blockedCache = await UserBlockedCache.init(user.id); - const blockerIds = await blockedCache.getAll(); - const renoteMutingsCache = await RenoteMutingsCache.init(user.id); - const renoteMutedIds = await renoteMutingsCache.getAll(); const optFilter = (n: ScyllaNote) => !n.renoteId || !!n.text || n.files.length > 0 || n.hasPoll;