forked from Mirrors/elk
fix(cache): return cached account as promise (#2623)
This commit is contained in:
parent
c00d6f7bf8
commit
748dd5e19f
1 changed files with 8 additions and 6 deletions
|
@ -23,7 +23,8 @@ export function fetchStatus(id: string, force = false): Promise<mastodon.v1.Stat
|
||||||
const key = `${server}:${userId}:status:${id}`
|
const key = `${server}:${userId}:status:${id}`
|
||||||
const cached = cache.get(key)
|
const cached = cache.get(key)
|
||||||
if (cached && !force)
|
if (cached && !force)
|
||||||
return cached
|
return Promise.resolve(cached)
|
||||||
|
|
||||||
const promise = useMastoClient().v1.statuses.$select(id).fetch()
|
const promise = useMastoClient().v1.statuses.$select(id).fetch()
|
||||||
.then((status) => {
|
.then((status) => {
|
||||||
cacheStatus(status)
|
cacheStatus(status)
|
||||||
|
@ -42,7 +43,8 @@ export function fetchAccountById(id?: string | null): Promise<mastodon.v1.Accoun
|
||||||
const key = `${server}:${userId}:account:${id}`
|
const key = `${server}:${userId}:account:${id}`
|
||||||
const cached = cache.get(key)
|
const cached = cache.get(key)
|
||||||
if (cached)
|
if (cached)
|
||||||
return cached
|
return Promise.resolve(cached)
|
||||||
|
|
||||||
const domain = getInstanceDomainFromServer(server)
|
const domain = getInstanceDomainFromServer(server)
|
||||||
const promise = useMastoClient().v1.accounts.$select(id).fetch()
|
const promise = useMastoClient().v1.accounts.$select(id).fetch()
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
|
@ -64,7 +66,7 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac
|
||||||
const key = `${server}:${userId}:account:${userAcct}`
|
const key = `${server}:${userId}:account:${userAcct}`
|
||||||
const cached = cache.get(key)
|
const cached = cache.get(key)
|
||||||
if (cached)
|
if (cached)
|
||||||
return cached
|
return Promise.resolve(cached)
|
||||||
|
|
||||||
async function lookupAccount() {
|
async function lookupAccount() {
|
||||||
const client = useMastoClient()
|
const client = useMastoClient()
|
||||||
|
@ -82,13 +84,13 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac
|
||||||
return account
|
return account
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = lookupAccount()
|
const promise = lookupAccount()
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
cacheAccount(r, server, true)
|
cacheAccount(r, server, true)
|
||||||
return r
|
return r
|
||||||
})
|
})
|
||||||
cache.set(key, account)
|
cache.set(key, promise)
|
||||||
return account
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAccountById(id?: string | null) {
|
export function useAccountById(id?: string | null) {
|
||||||
|
|
Loading…
Reference in a new issue