fix(cache): return cached account as promise (#2623)

zio/stable
Joaquín Sánchez 2024-02-25 20:43:34 +01:00 committed by GitHub
parent c00d6f7bf8
commit 748dd5e19f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 6 deletions

View File

@ -23,7 +23,8 @@ export function fetchStatus(id: string, force = false): Promise<mastodon.v1.Stat
const key = `${server}:${userId}:status:${id}`
const cached = cache.get(key)
if (cached && !force)
return cached
return Promise.resolve(cached)
const promise = useMastoClient().v1.statuses.$select(id).fetch()
.then((status) => {
cacheStatus(status)
@ -42,7 +43,8 @@ export function fetchAccountById(id?: string | null): Promise<mastodon.v1.Accoun
const key = `${server}:${userId}:account:${id}`
const cached = cache.get(key)
if (cached)
return cached
return Promise.resolve(cached)
const domain = getInstanceDomainFromServer(server)
const promise = useMastoClient().v1.accounts.$select(id).fetch()
.then((r) => {
@ -64,7 +66,7 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac
const key = `${server}:${userId}:account:${userAcct}`
const cached = cache.get(key)
if (cached)
return cached
return Promise.resolve(cached)
async function lookupAccount() {
const client = useMastoClient()
@ -82,13 +84,13 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac
return account
}
const account = lookupAccount()
const promise = lookupAccount()
.then((r) => {
cacheAccount(r, server, true)
return r
})
cache.set(key, account)
return account
cache.set(key, promise)
return promise
}
export function useAccountById(id?: string | null) {