Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce web requests #2420

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/state/queries/app-passwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const RQKEY = () => ['app-passwords']
export function useAppPasswordsQuery() {
return useQuery({
staleTime: STALE.MINUTES.FIVE,
refetchInterval: STALE.MINUTES.ONE,
queryKey: RQKEY(),
queryFn: async () => {
const res = await getAgent().com.atproto.server.listAppPasswords({})
Expand Down
1 change: 0 additions & 1 deletion src/state/queries/invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type InviteCodesQueryResponse = Exclude<
export function useInviteCodesQuery() {
return useQuery({
staleTime: STALE.MINUTES.FIVE,
refetchInterval: STALE.MINUTES.FIVE,
queryKey: ['inviteCodes'],
queryFn: async () => {
const res = await getAgent()
Expand Down
4 changes: 4 additions & 0 deletions src/state/queries/notifications/unread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {useMutedThreads} from '#/state/muted-threads'
import {RQKEY as RQKEY_NOTIFS} from './feed'
import {logger} from '#/logger'
import {truncateAndInvalidate} from '../util'
import {AppState} from 'react-native'

const UPDATE_INTERVAL = 30 * 1e3 // 30sec

Expand Down Expand Up @@ -97,6 +98,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
async checkUnread({invalidate}: {invalidate?: boolean} = {}) {
try {
if (!getAgent().session) return
if (AppState.currentState !== 'active') {
return
}

// count
const page = await fetchPage({
Expand Down
4 changes: 4 additions & 0 deletions src/state/queries/post-feed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback, useEffect, useRef} from 'react'
import {AppState} from 'react-native'
import {AppBskyFeedDefs, AppBskyFeedPost, PostModeration} from '@atproto/api'
import {
useInfiniteQuery,
Expand Down Expand Up @@ -312,6 +313,9 @@ export async function pollLatest(page: FeedPage | undefined) {
if (!page) {
return false
}
if (AppState.currentState !== 'active') {
return
}

logger.debug('usePostFeedQuery: pollLatest')
const post = await page.api.peekLatest()
Expand Down