Refetch some data on an interval (#2114)
* Match refetch intervals to stale time * Lower refetch interval for own-profilezio/stable
parent
47771b9066
commit
a924df4dcd
|
@ -8,7 +8,8 @@ export const RQKEY = () => ['app-passwords']
|
||||||
|
|
||||||
export function useAppPasswordsQuery() {
|
export function useAppPasswordsQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
|
refetchInterval: STALE.MINUTES.ONE,
|
||||||
queryKey: RQKEY(),
|
queryKey: RQKEY(),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await getAgent().com.atproto.server.listAppPasswords({})
|
const res = await getAgent().com.atproto.server.listAppPasswords({})
|
||||||
|
|
|
@ -5,6 +5,10 @@ export const PUBLIC_BSKY_AGENT = new BskyAgent({
|
||||||
})
|
})
|
||||||
|
|
||||||
export const STALE = {
|
export const STALE = {
|
||||||
|
SECONDS: {
|
||||||
|
FIFTEEN: 1e3 * 15,
|
||||||
|
THIRTY: 1e3 * 30,
|
||||||
|
},
|
||||||
MINUTES: {
|
MINUTES: {
|
||||||
ONE: 1e3 * 60,
|
ONE: 1e3 * 60,
|
||||||
FIVE: 1e3 * 60 * 5,
|
FIVE: 1e3 * 60 * 5,
|
||||||
|
|
|
@ -15,7 +15,8 @@ export type InviteCodesQueryResponse = Exclude<
|
||||||
>
|
>
|
||||||
export function useInviteCodesQuery() {
|
export function useInviteCodesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.HOURS.ONE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
|
refetchInterval: STALE.MINUTES.FIVE,
|
||||||
queryKey: ['inviteCodes'],
|
queryKey: ['inviteCodes'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await getAgent()
|
const res = await getAgent()
|
||||||
|
|
|
@ -28,8 +28,9 @@ export const preferencesQueryKey = ['getPreferences']
|
||||||
|
|
||||||
export function usePreferencesQuery() {
|
export function usePreferencesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.ONE,
|
staleTime: STALE.SECONDS.FIFTEEN,
|
||||||
structuralSharing: true,
|
structuralSharing: true,
|
||||||
|
refetchInterval: STALE.SECONDS.FIFTEEN,
|
||||||
queryKey: preferencesQueryKey,
|
queryKey: preferencesQueryKey,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const agent = getAgent()
|
const agent = getAgent()
|
||||||
|
|
|
@ -26,12 +26,18 @@ import {track} from '#/lib/analytics/analytics'
|
||||||
export const RQKEY = (did: string) => ['profile', did]
|
export const RQKEY = (did: string) => ['profile', did]
|
||||||
|
|
||||||
export function useProfileQuery({did}: {did: string | undefined}) {
|
export function useProfileQuery({did}: {did: string | undefined}) {
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
const isCurrentAccount = did === currentAccount?.did
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
// WARNING
|
// WARNING
|
||||||
// this staleTime is load-bearing
|
// this staleTime is load-bearing
|
||||||
// if you remove it, the UI infinite-loops
|
// if you remove it, the UI infinite-loops
|
||||||
// -prf
|
// -prf
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: isCurrentAccount ? STALE.SECONDS.THIRTY : STALE.MINUTES.FIVE,
|
||||||
|
refetchInterval: isCurrentAccount
|
||||||
|
? STALE.SECONDS.THIRTY
|
||||||
|
: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY(did || ''),
|
queryKey: RQKEY(did || ''),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await getAgent().getProfile({actor: did || ''})
|
const res = await getAgent().getProfile({actor: did || ''})
|
||||||
|
|
Loading…
Reference in New Issue