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 profile
zio/stable
Paul Frazee 2023-11-29 20:27:39 -08:00 committed by GitHub
parent c3e97fee1d
commit fcd22d4ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 8 additions and 26 deletions

View File

@ -2,7 +2,6 @@ import {AppBskyGraphGetBlocks} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
export const RQKEY = () => ['my-blocked-accounts'] export const RQKEY = () => ['my-blocked-accounts']
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -15,7 +14,6 @@ export function useMyBlockedAccountsQuery() {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(), queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.graph.getBlocks({ const res = await getAgent().app.bsky.graph.getBlocks({

View File

@ -2,7 +2,6 @@ import {AppBskyGraphGetMutes} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
export const RQKEY = () => ['my-muted-accounts'] export const RQKEY = () => ['my-muted-accounts']
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -15,7 +14,6 @@ export function useMyMutedAccountsQuery() {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(), queryKey: RQKEY(),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.graph.getMutes({ const res = await getAgent().app.bsky.graph.getMutes({

View File

@ -119,7 +119,8 @@ function groupNotifications(
Math.abs(ts2 - ts) < MS_2DAY && Math.abs(ts2 - ts) < MS_2DAY &&
notif.reason === groupedNotif.notification.reason && notif.reason === groupedNotif.notification.reason &&
notif.reasonSubject === groupedNotif.notification.reasonSubject && 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 = groupedNotif.additional || []
groupedNotif.additional.push(notif) groupedNotif.additional.push(notif)

View File

@ -2,7 +2,6 @@ import {AppBskyFeedGetLikes} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30 const PAGE_SIZE = 30
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -18,7 +17,6 @@ export function usePostLikedByQuery(resolvedUri: string | undefined) {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(resolvedUri || ''), queryKey: RQKEY(resolvedUri || ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().getLikes({ const res = await getAgent().getLikes({

View File

@ -2,7 +2,6 @@ import {AppBskyFeedGetRepostedBy} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30 const PAGE_SIZE = 30
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -18,7 +17,6 @@ export function usePostRepostedByQuery(resolvedUri: string | undefined) {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(resolvedUri || ''), queryKey: RQKEY(resolvedUri || ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().getRepostedBy({ const res = await getAgent().getRepostedBy({

View File

@ -7,7 +7,6 @@ import {useQuery, useQueryClient, QueryClient} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
import {STALE} from '#/state/queries'
import {findPostInQueryData as findPostInFeedQueryData} from './post-feed' import {findPostInQueryData as findPostInFeedQueryData} from './post-feed'
import {findPostInQueryData as findPostInNotifsQueryData} from './notifications/feed' import {findPostInQueryData as findPostInNotifsQueryData} from './notifications/feed'
import {precacheThreadPosts as precacheResolvedUris} from './resolve-uri' import {precacheThreadPosts as precacheResolvedUris} from './resolve-uri'
@ -65,7 +64,6 @@ export type ThreadNode =
export function usePostThreadQuery(uri: string | undefined) { export function usePostThreadQuery(uri: string | undefined) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
return useQuery<ThreadNode, Error>({ return useQuery<ThreadNode, Error>({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(uri || ''), queryKey: RQKEY(uri || ''),
async queryFn() { async queryFn() {
const res = await getAgent().getPostThread({uri: uri!}) const res = await getAgent().getPostThread({uri: uri!})

View File

@ -4,13 +4,11 @@ import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {updatePostShadow} from '#/state/cache/post-shadow' import {updatePostShadow} from '#/state/cache/post-shadow'
import {STALE} from '#/state/queries'
export const RQKEY = (postUri: string) => ['post', postUri] export const RQKEY = (postUri: string) => ['post', postUri]
export function usePostQuery(uri: string | undefined) { export function usePostQuery(uri: string | undefined) {
return useQuery<AppBskyFeedDefs.PostView>({ return useQuery<AppBskyFeedDefs.PostView>({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(uri || ''), queryKey: RQKEY(uri || ''),
async queryFn() { async queryFn() {
const res = await getAgent().getPosts({uris: [uri!]}) const res = await getAgent().getPosts({uris: [uri!]})
@ -29,7 +27,6 @@ export function useGetPost() {
return React.useCallback( return React.useCallback(
async ({uri}: {uri: string}) => { async ({uri}: {uri: string}) => {
return queryClient.fetchQuery({ return queryClient.fetchQuery({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(uri || ''), queryKey: RQKEY(uri || ''),
async queryFn() { async queryFn() {
const urip = new AtUri(uri) const urip = new AtUri(uri)

View File

@ -2,7 +2,6 @@ import {AppBskyFeedGetActorFeeds} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30 const PAGE_SIZE = 30
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -22,7 +21,6 @@ export function useProfileFeedgensQuery(
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(did), queryKey: RQKEY(did),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.feed.getActorFeeds({ const res = await getAgent().app.bsky.feed.getActorFeeds({

View File

@ -2,7 +2,6 @@ import {AppBskyGraphGetFollowers} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30 const PAGE_SIZE = 30
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -17,7 +16,6 @@ export function useProfileFollowersQuery(did: string | undefined) {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.FIVE,
queryKey: RQKEY(did || ''), queryKey: RQKEY(did || ''),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.graph.getFollowers({ const res = await getAgent().app.bsky.graph.getFollowers({

View File

@ -1,8 +1,6 @@
import {AppBskyGraphGetLists} from '@atproto/api' import {AppBskyGraphGetLists} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30 const PAGE_SIZE = 30
type RQPageParam = string | undefined type RQPageParam = string | undefined
@ -18,7 +16,6 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
QueryKey, QueryKey,
RQPageParam RQPageParam
>({ >({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(did), queryKey: RQKEY(did),
async queryFn({pageParam}: {pageParam: RQPageParam}) { async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await getAgent().app.bsky.graph.getLists({ const res = await getAgent().app.bsky.graph.getLists({

View File

@ -21,6 +21,10 @@ export const RQKEY = (did: string) => ['profile', did]
export function useProfileQuery({did}: {did: string | undefined}) { export function useProfileQuery({did}: {did: string | undefined}) {
return useQuery({ return useQuery({
// WARNING
// this staleTime is load-bearing
// if you remove it, the UI infinite-loops
// -prf
staleTime: STALE.MINUTES.FIVE, staleTime: STALE.MINUTES.FIVE,
queryKey: RQKEY(did || ''), queryKey: RQKEY(did || ''),
queryFn: async () => { queryFn: async () => {

View File

@ -23,7 +23,7 @@ export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
export function useResolveDidQuery(didOrHandle: string | undefined) { export function useResolveDidQuery(didOrHandle: string | undefined) {
return useQuery<string, Error>({ return useQuery<string, Error>({
staleTime: STALE.INFINITY, staleTime: STALE.HOURS.ONE,
queryKey: RQKEY(didOrHandle || ''), queryKey: RQKEY(didOrHandle || ''),
async queryFn() { async queryFn() {
if (!didOrHandle) { if (!didOrHandle) {

View File

@ -1,13 +1,10 @@
import {BskyAgent} from '@atproto/api' import {BskyAgent} from '@atproto/api'
import {useQuery} from '@tanstack/react-query' import {useQuery} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
export const RQKEY = (serviceUrl: string) => ['service', serviceUrl] export const RQKEY = (serviceUrl: string) => ['service', serviceUrl]
export function useServiceQuery(serviceUrl: string) { export function useServiceQuery(serviceUrl: string) {
return useQuery({ return useQuery({
staleTime: STALE.HOURS.ONE,
queryKey: RQKEY(serviceUrl), queryKey: RQKEY(serviceUrl),
queryFn: async () => { queryFn: async () => {
const agent = new BskyAgent({service: serviceUrl}) const agent = new BskyAgent({service: serviceUrl})

View File

@ -90,7 +90,7 @@ export function useGetSuggestedFollowersByActor() {
return React.useCallback( return React.useCallback(
async (actor: string) => { async (actor: string) => {
const res = await queryClient.fetchQuery({ const res = await queryClient.fetchQuery({
staleTime: 60 * 1000, staleTime: STALE.MINUTES.ONE,
queryKey: suggestedFollowsByActorQueryKey(actor), queryKey: suggestedFollowsByActorQueryKey(actor),
queryFn: async () => { queryFn: async () => {
const res = const res =