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 {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({
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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!})
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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 () => {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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})
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
Loading…
Reference in New Issue