refactor: promise at once

This commit is contained in:
Namekuji 2023-08-07 07:02:51 -04:00
parent 52e9ba73df
commit 17161c9ba2
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532

View file

@ -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;