Reduce web requests (#2420)
* Stop auto-refetching app passwords and invites on an interval * Don't poll for posts or notifs if the app/tab isnt focusedzio/stable
parent
8a4a8af61c
commit
db62f27241
|
@ -9,7 +9,6 @@ export const RQKEY = () => ['app-passwords']
|
||||||
export function useAppPasswordsQuery() {
|
export function useAppPasswordsQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
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({})
|
||||||
|
|
|
@ -16,7 +16,6 @@ export type InviteCodesQueryResponse = Exclude<
|
||||||
export function useInviteCodesQuery() {
|
export function useInviteCodesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
refetchInterval: STALE.MINUTES.FIVE,
|
|
||||||
queryKey: ['inviteCodes'],
|
queryKey: ['inviteCodes'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await getAgent()
|
const res = await getAgent()
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {useMutedThreads} from '#/state/muted-threads'
|
||||||
import {RQKEY as RQKEY_NOTIFS} from './feed'
|
import {RQKEY as RQKEY_NOTIFS} from './feed'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {truncateAndInvalidate} from '../util'
|
import {truncateAndInvalidate} from '../util'
|
||||||
|
import {AppState} from 'react-native'
|
||||||
|
|
||||||
const UPDATE_INTERVAL = 30 * 1e3 // 30sec
|
const UPDATE_INTERVAL = 30 * 1e3 // 30sec
|
||||||
|
|
||||||
|
@ -97,6 +98,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
async checkUnread({invalidate}: {invalidate?: boolean} = {}) {
|
async checkUnread({invalidate}: {invalidate?: boolean} = {}) {
|
||||||
try {
|
try {
|
||||||
if (!getAgent().session) return
|
if (!getAgent().session) return
|
||||||
|
if (AppState.currentState !== 'active') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// count
|
// count
|
||||||
const page = await fetchPage({
|
const page = await fetchPage({
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, {useCallback, useEffect, useRef} from 'react'
|
import React, {useCallback, useEffect, useRef} from 'react'
|
||||||
|
import {AppState} from 'react-native'
|
||||||
import {AppBskyFeedDefs, AppBskyFeedPost, PostModeration} from '@atproto/api'
|
import {AppBskyFeedDefs, AppBskyFeedPost, PostModeration} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
|
@ -312,6 +313,9 @@ export async function pollLatest(page: FeedPage | undefined) {
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (AppState.currentState !== 'active') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug('usePostFeedQuery: pollLatest')
|
logger.debug('usePostFeedQuery: pollLatest')
|
||||||
const post = await page.api.peekLatest()
|
const post = await page.api.peekLatest()
|
||||||
|
|
Loading…
Reference in New Issue