Skip to content

Commit

Permalink
Fix profile not waiting for cache response
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 5, 2024
1 parent 6f23da1 commit f1c07af
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pages/api/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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(
Expand All @@ -120,6 +120,7 @@ export async function getProfilesServer(
)
})
})
await Promise.all(saveToRedisPromises)

return [...profiles, ...fetchedProfiles]
}

0 comments on commit f1c07af

Please sign in to comment.