Adjust stale-caches and dont group read&unread notifs together (#2041)
* Dont group read & unread notifications together * Remove and reduce some stale cache times * Keep the staleTime on the post-feed * Bring back the load-bearing staletime on profilezio/stable
parent
c3e97fee1d
commit
fcd22d4ccb
|
@ -2,7 +2,6 @@ import {AppBskyGraphGetBlocks} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = () => ['my-blocked-accounts']
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -15,7 +14,6 @@ export function useMyBlockedAccountsQuery() {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getBlocks({
|
||||
|
|
|
@ -2,7 +2,6 @@ import {AppBskyGraphGetMutes} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = () => ['my-muted-accounts']
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -15,7 +14,6 @@ export function useMyMutedAccountsQuery() {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getMutes({
|
||||
|
|
|
@ -119,7 +119,8 @@ function groupNotifications(
|
|||
Math.abs(ts2 - ts) < MS_2DAY &&
|
||||
notif.reason === groupedNotif.notification.reason &&
|
||||
notif.reasonSubject === groupedNotif.notification.reasonSubject &&
|
||||
notif.author.did !== groupedNotif.notification.author.did
|
||||
notif.author.did !== groupedNotif.notification.author.did &&
|
||||
notif.isRead === groupedNotif.notification.isRead
|
||||
) {
|
||||
groupedNotif.additional = groupedNotif.additional || []
|
||||
groupedNotif.additional.push(notif)
|
||||
|
|
|
@ -2,7 +2,6 @@ import {AppBskyFeedGetLikes} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -18,7 +17,6 @@ export function usePostLikedByQuery(resolvedUri: string | undefined) {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(resolvedUri || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().getLikes({
|
||||
|
|
|
@ -2,7 +2,6 @@ import {AppBskyFeedGetRepostedBy} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -18,7 +17,6 @@ export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(resolvedUri || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().getRepostedBy({
|
||||
|
|
|
@ -7,7 +7,6 @@ import {useQuery, useQueryClient, QueryClient} from '@tanstack/react-query'
|
|||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {findPostInQueryData as findPostInFeedQueryData} from './post-feed'
|
||||
import {findPostInQueryData as findPostInNotifsQueryData} from './notifications/feed'
|
||||
import {precacheThreadPosts as precacheResolvedUris} from './resolve-uri'
|
||||
|
@ -65,7 +64,6 @@ export type ThreadNode =
|
|||
export function usePostThreadQuery(uri: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
return useQuery<ThreadNode, Error>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().getPostThread({uri: uri!})
|
||||
|
|
|
@ -4,13 +4,11 @@ import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
|||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = (postUri: string) => ['post', postUri]
|
||||
|
||||
export function usePostQuery(uri: string | undefined) {
|
||||
return useQuery<AppBskyFeedDefs.PostView>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().getPosts({uris: [uri!]})
|
||||
|
@ -29,7 +27,6 @@ export function useGetPost() {
|
|||
return React.useCallback(
|
||||
async ({uri}: {uri: string}) => {
|
||||
return queryClient.fetchQuery({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const urip = new AtUri(uri)
|
||||
|
|
|
@ -2,7 +2,6 @@ import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -22,7 +21,6 @@ export function useProfileFeedgensQuery(
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(did),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.feed.getActorFeeds({
|
||||
|
|
|
@ -2,7 +2,6 @@ import {AppBskyGraphGetFollowers} from '@atproto/api'
|
|||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -17,7 +16,6 @@ export function useProfileFollowersQuery(did: string | undefined) {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(did || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getFollowers({
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import {AppBskyGraphGetLists} from '@atproto/api'
|
||||
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -18,7 +16,6 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
|||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(did),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getLists({
|
||||
|
|
|
@ -21,6 +21,10 @@ export const RQKEY = (did: string) => ['profile', did]
|
|||
|
||||
export function useProfileQuery({did}: {did: string | undefined}) {
|
||||
return useQuery({
|
||||
// WARNING
|
||||
// this staleTime is load-bearing
|
||||
// if you remove it, the UI infinite-loops
|
||||
// -prf
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(did || ''),
|
||||
queryFn: async () => {
|
||||
|
|
|
@ -23,7 +23,7 @@ export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
|
|||
|
||||
export function useResolveDidQuery(didOrHandle: string | undefined) {
|
||||
return useQuery<string, Error>({
|
||||
staleTime: STALE.INFINITY,
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
queryKey: RQKEY(didOrHandle || ''),
|
||||
async queryFn() {
|
||||
if (!didOrHandle) {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import {BskyAgent} from '@atproto/api'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = (serviceUrl: string) => ['service', serviceUrl]
|
||||
|
||||
export function useServiceQuery(serviceUrl: string) {
|
||||
return useQuery({
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
queryKey: RQKEY(serviceUrl),
|
||||
queryFn: async () => {
|
||||
const agent = new BskyAgent({service: serviceUrl})
|
||||
|
|
|
@ -90,7 +90,7 @@ export function useGetSuggestedFollowersByActor() {
|
|||
return React.useCallback(
|
||||
async (actor: string) => {
|
||||
const res = await queryClient.fetchQuery({
|
||||
staleTime: 60 * 1000,
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: suggestedFollowsByActorQueryKey(actor),
|
||||
queryFn: async () => {
|
||||
const res =
|
||||
|
|
Loading…
Reference in New Issue