Caching heuristics (#1938)

* Tempfix profile load

* First pass at staleTime
This commit is contained in:
Eric Bailey 2023-11-16 17:28:50 -06:00 committed by GitHub
parent f89dc63801
commit 6dfb2a232f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 122 additions and 22 deletions

View file

@ -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