From f1c07af4c453a2d2dc1e4b0cef492eb626994803 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 5 Jul 2024 20:07:31 +0700 Subject: [PATCH] Fix profile not waiting for cache response --- src/pages/api/profiles.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/api/profiles.ts b/src/pages/api/profiles.ts index df014f1c6..1b5c765c9 100644 --- a/src/pages/api/profiles.ts +++ b/src/pages/api/profiles.ts @@ -86,7 +86,7 @@ export async function getProfilesServer( const profiles: SubsocialProfile[] = [] const needToFetch: string[] = [] const promises = addresses.map(async (address) => { - redisCallWrapper(async (redis) => { + return redisCallWrapper(async (redis) => { const [profile, isInvalidated] = await Promise.all([ redis?.get(getProfileRedisKey(address)), redis?.get(getInvalidatedProfileRedisKey(address)), @@ -109,7 +109,7 @@ export async function getProfilesServer( profilesMap.set(profile.address, profile) }) - needToFetch.map((address) => { + const saveToRedisPromises = needToFetch.map((address) => { const profile = profilesMap.get(address) ?? null redisCallWrapper(async (redis) => { await redis?.set( @@ -120,6 +120,7 @@ export async function getProfilesServer( ) }) }) + await Promise.all(saveToRedisPromises) return [...profiles, ...fetchedProfiles] }