Caching heuristics (#1938)
* Tempfix profile load * First pass at staleTime
This commit is contained in:
parent
f89dc63801
commit
6dfb2a232f
30 changed files with 122 additions and 22 deletions
|
@ -16,12 +16,14 @@ import {Shadow} from '#/state/cache/types'
|
|||
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
||||
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
||||
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = (did: string) => ['profile', did]
|
||||
|
||||
export function useProfileQuery({did}: {did: string | undefined}) {
|
||||
const {agent} = useSession()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(did || ''),
|
||||
queryFn: async () => {
|
||||
const res = await agent.getProfile({actor: did || ''})
|
||||
|
@ -304,6 +306,7 @@ function useProfileMuteMutation() {
|
|||
|
||||
function useProfileUnmuteMutation() {
|
||||
const {agent} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({
|
||||
mutationFn: async ({did}) => {
|
||||
await agent.unmute(did)
|
||||
|
@ -316,6 +319,9 @@ function useProfileUnmuteMutation() {
|
|||
})
|
||||
}
|
||||
},
|
||||
onSuccess() {
|
||||
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||
},
|
||||
onError(error, variables) {
|
||||
if (!variables.skipOptimistic) {
|
||||
// revert the optimistic update
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue