Additional reductions in request traffic (#2169)
* Dont poll for new content on profiles * Drop the whenAppReady query after new post to reduce traffic overhead * Reduce getPosts calls in notifs to only use them when neededzio/stable
parent
ab04074197
commit
99cf6b626f
|
@ -76,6 +76,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
queryClient,
|
queryClient,
|
||||||
moderationOpts,
|
moderationOpts,
|
||||||
threadMutes,
|
threadMutes,
|
||||||
|
fetchAdditionalData: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
queryClient,
|
queryClient,
|
||||||
moderationOpts,
|
moderationOpts,
|
||||||
threadMutes,
|
threadMutes,
|
||||||
|
|
||||||
|
// only fetch subjects when the page is going to be used
|
||||||
|
// in the notifications query, otherwise skip it
|
||||||
|
fetchAdditionalData: !!invalidate,
|
||||||
})
|
})
|
||||||
const unreadCount = countUnread(page)
|
const unreadCount = countUnread(page)
|
||||||
const unreadCountStr =
|
const unreadCountStr =
|
||||||
|
|
|
@ -27,12 +27,14 @@ export async function fetchPage({
|
||||||
queryClient,
|
queryClient,
|
||||||
moderationOpts,
|
moderationOpts,
|
||||||
threadMutes,
|
threadMutes,
|
||||||
|
fetchAdditionalData,
|
||||||
}: {
|
}: {
|
||||||
cursor: string | undefined
|
cursor: string | undefined
|
||||||
limit: number
|
limit: number
|
||||||
queryClient: QueryClient
|
queryClient: QueryClient
|
||||||
moderationOpts: ModerationOpts | undefined
|
moderationOpts: ModerationOpts | undefined
|
||||||
threadMutes: string[]
|
threadMutes: string[]
|
||||||
|
fetchAdditionalData: boolean
|
||||||
}): Promise<FeedPage> {
|
}): Promise<FeedPage> {
|
||||||
const res = await getAgent().listNotifications({
|
const res = await getAgent().listNotifications({
|
||||||
limit,
|
limit,
|
||||||
|
@ -49,6 +51,7 @@ export async function fetchPage({
|
||||||
|
|
||||||
// we fetch subjects of notifications (usually posts) now instead of lazily
|
// we fetch subjects of notifications (usually posts) now instead of lazily
|
||||||
// in the UI to avoid relayouts
|
// in the UI to avoid relayouts
|
||||||
|
if (fetchAdditionalData) {
|
||||||
const subjects = await fetchSubjects(notifsGrouped)
|
const subjects = await fetchSubjects(notifsGrouped)
|
||||||
for (const notif of notifsGrouped) {
|
for (const notif of notifsGrouped) {
|
||||||
if (notif.subjectUri) {
|
if (notif.subjectUri) {
|
||||||
|
@ -58,6 +61,7 @@ export async function fetchPage({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// apply thread muting
|
// apply thread muting
|
||||||
notifsGrouped = notifsGrouped.filter(
|
notifsGrouped = notifsGrouped.filter(
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {AppBskyFeedGetPosts, RichText} from '@atproto/api'
|
import {RichText} from '@atproto/api'
|
||||||
import {useAnalytics} from 'lib/analytics/analytics'
|
import {useAnalytics} from 'lib/analytics/analytics'
|
||||||
import {useIsKeyboardVisible} from 'lib/hooks/useIsKeyboardVisible'
|
import {useIsKeyboardVisible} from 'lib/hooks/useIsKeyboardVisible'
|
||||||
import {ExternalEmbed} from './ExternalEmbed'
|
import {ExternalEmbed} from './ExternalEmbed'
|
||||||
|
@ -60,7 +60,6 @@ import {
|
||||||
import {useSession, getAgent} from '#/state/session'
|
import {useSession, getAgent} from '#/state/session'
|
||||||
import {useProfileQuery} from '#/state/queries/profile'
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useComposerControls} from '#/state/shell/composer'
|
import {useComposerControls} from '#/state/shell/composer'
|
||||||
import {until} from '#/lib/async/until'
|
|
||||||
import {emitPostCreated} from '#/state/events'
|
import {emitPostCreated} from '#/state/events'
|
||||||
import {ThreadgateSetting} from '#/state/queries/threadgate'
|
import {ThreadgateSetting} from '#/state/queries/threadgate'
|
||||||
|
|
||||||
|
@ -246,9 +245,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
if (replyTo && replyTo.uri) track('Post:Reply')
|
if (replyTo && replyTo.uri) track('Post:Reply')
|
||||||
}
|
}
|
||||||
if (postUri && !replyTo) {
|
if (postUri && !replyTo) {
|
||||||
whenAppViewReady(postUri).then(() => {
|
|
||||||
emitPostCreated()
|
emitPostCreated()
|
||||||
})
|
|
||||||
}
|
}
|
||||||
setLangPrefs.savePostLanguageToHistory()
|
setLangPrefs.savePostLanguageToHistory()
|
||||||
onPost?.()
|
onPost?.()
|
||||||
|
@ -553,15 +550,3 @@ const styles = StyleSheet.create({
|
||||||
borderTopWidth: 1,
|
borderTopWidth: 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
async function whenAppViewReady(uri: string) {
|
|
||||||
await until(
|
|
||||||
5, // 5 tries
|
|
||||||
1e3, // 1s delay between tries
|
|
||||||
(res: AppBskyFeedGetPosts.Response) => !!res.data.posts[0],
|
|
||||||
() =>
|
|
||||||
getAgent().getPosts({
|
|
||||||
uris: [uri],
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -441,7 +441,6 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
|
||||||
testID="postsFeed"
|
testID="postsFeed"
|
||||||
enabled={isFocused}
|
enabled={isFocused}
|
||||||
feed={feed}
|
feed={feed}
|
||||||
pollInterval={30e3}
|
|
||||||
scrollElRef={scrollElRef}
|
scrollElRef={scrollElRef}
|
||||||
onHasNew={setHasNew}
|
onHasNew={setHasNew}
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
|
|
Loading…
Reference in New Issue