remove precacheThreadPostProfiles (#3729)
* remove `precacheThreadPostProfiles` * add `displayName` to `PreviewableUserAvatar` * memo * use `precacheProfile` * pass `profile` directly to `PreviewableUserAvatar` * update the `UserAvatar`'s props * remove feed cache * one more spot * rm unused queryClient * Don't call fn unnecessarily * Preload for display name too * try notification item * add to feeditem * and finally, precache for post threads * timestamp * Fix * onBeforePress --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
parent
ce85375c85
commit
7eb1444f2c
17 changed files with 119 additions and 168 deletions
|
@ -12,7 +12,6 @@ import {
|
|||
QueryClient,
|
||||
QueryKey,
|
||||
useInfiniteQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {HomeFeedAPI} from '#/lib/api/feed/home'
|
||||
|
@ -33,7 +32,6 @@ import {BSKY_FEED_OWNER_DIDS} from 'lib/constants'
|
|||
import {KnownError} from '#/view/com/posts/FeedErrorMessage'
|
||||
import {useFeedTuners} from '../preferences/feed-tuners'
|
||||
import {useModerationOpts} from './preferences'
|
||||
import {precacheFeedPostProfiles} from './profile'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
|
||||
type ActorDid = string
|
||||
|
@ -102,7 +100,6 @@ export function usePostFeedQuery(
|
|||
params?: FeedParams,
|
||||
opts?: {enabled?: boolean; ignoreFilterFor?: string},
|
||||
) {
|
||||
const queryClient = useQueryClient()
|
||||
const feedTuners = useFeedTuners(feedDesc)
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
|
@ -151,7 +148,6 @@ export function usePostFeedQuery(
|
|||
|
||||
try {
|
||||
const res = await api.fetch({cursor, limit: PAGE_SIZE})
|
||||
precacheFeedPostProfiles(queryClient, res.feed)
|
||||
|
||||
/*
|
||||
* If this is a public view, we need to check if posts fail moderation.
|
||||
|
|
|
@ -11,7 +11,6 @@ import {useAgent} from '#/state/session'
|
|||
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from 'state/queries/search-posts'
|
||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
|
||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
|
||||
import {precacheThreadPostProfiles} from './profile'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
|
||||
const RQKEY_ROOT = 'post-thread'
|
||||
|
@ -73,9 +72,7 @@ export function usePostThreadQuery(uri: string | undefined) {
|
|||
async queryFn() {
|
||||
const res = await getAgent().getPostThread({uri: uri!})
|
||||
if (res.success) {
|
||||
const nodes = responseToThreadNodes(res.data.thread)
|
||||
precacheThreadPostProfiles(queryClient, nodes)
|
||||
return nodes
|
||||
return responseToThreadNodes(res.data.thread)
|
||||
}
|
||||
return {type: 'unknown', uri: uri!}
|
||||
},
|
||||
|
|
|
@ -4,9 +4,6 @@ import {
|
|||
AppBskyActorDefs,
|
||||
AppBskyActorGetProfile,
|
||||
AppBskyActorProfile,
|
||||
AppBskyEmbedRecord,
|
||||
AppBskyEmbedRecordWithMedia,
|
||||
AppBskyFeedDefs,
|
||||
AtUri,
|
||||
BskyAgent,
|
||||
} from '@atproto/api'
|
||||
|
@ -29,7 +26,6 @@ import {updateProfileShadow} from '../cache/profile-shadow'
|
|||
import {useAgent, useSession} from '../session'
|
||||
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
||||
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
||||
import {ThreadNode} from './post-thread'
|
||||
|
||||
const RQKEY_ROOT = 'profile'
|
||||
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||
|
@ -477,56 +473,6 @@ export function precacheProfile(
|
|||
queryClient.setQueryData(profileBasicQueryKey(profile.did), profile)
|
||||
}
|
||||
|
||||
export function precacheFeedPostProfiles(
|
||||
queryClient: QueryClient,
|
||||
posts: AppBskyFeedDefs.FeedViewPost[],
|
||||
) {
|
||||
for (const post of posts) {
|
||||
// Save the author of the post every time
|
||||
precacheProfile(queryClient, post.post.author)
|
||||
precachePostEmbedProfile(queryClient, post.post.embed)
|
||||
|
||||
// Cache parent author and embeds
|
||||
const parent = post.reply?.parent
|
||||
if (AppBskyFeedDefs.isPostView(parent)) {
|
||||
precacheProfile(queryClient, parent.author)
|
||||
precachePostEmbedProfile(queryClient, parent.embed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function precachePostEmbedProfile(
|
||||
queryClient: QueryClient,
|
||||
embed: AppBskyFeedDefs.PostView['embed'],
|
||||
) {
|
||||
if (AppBskyEmbedRecord.isView(embed)) {
|
||||
if (AppBskyEmbedRecord.isViewRecord(embed.record)) {
|
||||
precacheProfile(queryClient, embed.record.author)
|
||||
}
|
||||
} else if (AppBskyEmbedRecordWithMedia.isView(embed)) {
|
||||
if (AppBskyEmbedRecord.isViewRecord(embed.record.record)) {
|
||||
precacheProfile(queryClient, embed.record.record.author)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function precacheThreadPostProfiles(
|
||||
queryClient: QueryClient,
|
||||
node: ThreadNode,
|
||||
) {
|
||||
if (node.type === 'post') {
|
||||
precacheProfile(queryClient, node.post.author)
|
||||
if (node.parent) {
|
||||
precacheThreadPostProfiles(queryClient, node.parent)
|
||||
}
|
||||
if (node.replies?.length) {
|
||||
for (const reply of node.replies) {
|
||||
precacheThreadPostProfiles(queryClient, reply)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function whenAppViewReady(
|
||||
getAgent: () => BskyAgent,
|
||||
actor: string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue