Traffic reduction and tuned caching strats (#2215)
* Update the feed to only check latest on focus after 30s, but to do a full reset on focus after 1 hour to avoid very stale data * Remove the isFeedPublic query * Fix: avoid double next-page fetches * Reduce some poll intervals to reduce server load * Guard against double-fires of fetchNextPage * Reduce polling on blurred screens
This commit is contained in:
parent
dd074371cf
commit
2a712630b4
8 changed files with 83 additions and 151 deletions
|
@ -1,7 +1,7 @@
|
|||
import React, {useMemo, useCallback} from 'react'
|
||||
import {Dimensions, StyleSheet, View, ActivityIndicator} from 'react-native'
|
||||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useIsFocused, useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {HeartIcon, HeartIconSolid} from 'lib/icons'
|
||||
|
@ -42,11 +42,7 @@ import {logger} from '#/logger'
|
|||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {
|
||||
useFeedSourceInfoQuery,
|
||||
FeedSourceFeedInfo,
|
||||
useIsFeedPublicQuery,
|
||||
} from '#/state/queries/feed'
|
||||
import {useFeedSourceInfoQuery, FeedSourceFeedInfo} from '#/state/queries/feed'
|
||||
import {useResolveUriQuery} from '#/state/queries/resolve-uri'
|
||||
import {
|
||||
UsePreferencesQueryResponse,
|
||||
|
@ -132,10 +128,8 @@ export function ProfileFeedScreen(props: Props) {
|
|||
function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
const {data: info} = useFeedSourceInfoQuery({uri: feedUri})
|
||||
const {isLoading: isPublicStatusLoading, data: isPublicResponse} =
|
||||
useIsFeedPublicQuery({uri: feedUri})
|
||||
|
||||
if (!preferences || !info || isPublicStatusLoading) {
|
||||
if (!preferences || !info) {
|
||||
return (
|
||||
<CenteredView>
|
||||
<View style={s.p20}>
|
||||
|
@ -149,7 +143,6 @@ function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
|
|||
<ProfileFeedScreenInner
|
||||
preferences={preferences}
|
||||
feedInfo={info as FeedSourceFeedInfo}
|
||||
isPublicResponse={isPublicResponse}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
@ -157,11 +150,9 @@ function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
|
|||
export function ProfileFeedScreenInner({
|
||||
preferences,
|
||||
feedInfo,
|
||||
isPublicResponse,
|
||||
}: {
|
||||
preferences: UsePreferencesQueryResponse
|
||||
feedInfo: FeedSourceFeedInfo
|
||||
isPublicResponse: ReturnType<typeof useIsFeedPublicQuery>['data']
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const pal = usePalette('default')
|
||||
|
@ -170,6 +161,7 @@ export function ProfileFeedScreenInner({
|
|||
const {openComposer} = useComposerControls()
|
||||
const {track} = useAnalytics()
|
||||
const feedSectionRef = React.useRef<SectionRef>(null)
|
||||
const isScreenFocused = useIsFocused()
|
||||
|
||||
const {
|
||||
mutateAsync: saveFeed,
|
||||
|
@ -205,6 +197,9 @@ export function ProfileFeedScreenInner({
|
|||
|
||||
useSetTitle(feedInfo?.displayName)
|
||||
|
||||
// event handlers
|
||||
//
|
||||
|
||||
const onToggleSaved = React.useCallback(async () => {
|
||||
try {
|
||||
Haptics.default()
|
||||
|
@ -398,21 +393,15 @@ export function ProfileFeedScreenInner({
|
|||
isHeaderReady={true}
|
||||
renderHeader={renderHeader}
|
||||
onCurrentPageSelected={onCurrentPageSelected}>
|
||||
{({headerHeight, scrollElRef, isFocused}) =>
|
||||
isPublicResponse?.isPublic ? (
|
||||
<FeedSection
|
||||
ref={feedSectionRef}
|
||||
feed={`feedgen|${feedInfo.uri}`}
|
||||
headerHeight={headerHeight}
|
||||
scrollElRef={scrollElRef as ListRef}
|
||||
isFocused={isFocused}
|
||||
/>
|
||||
) : (
|
||||
<CenteredView sideBorders style={[{paddingTop: headerHeight}]}>
|
||||
<NonPublicFeedMessage rawError={isPublicResponse?.error} />
|
||||
</CenteredView>
|
||||
)
|
||||
}
|
||||
{({headerHeight, scrollElRef, isFocused}) => (
|
||||
<FeedSection
|
||||
ref={feedSectionRef}
|
||||
feed={`feedgen|${feedInfo.uri}`}
|
||||
headerHeight={headerHeight}
|
||||
scrollElRef={scrollElRef as ListRef}
|
||||
isFocused={isScreenFocused && isFocused}
|
||||
/>
|
||||
)}
|
||||
{({headerHeight, scrollElRef}) => (
|
||||
<AboutSection
|
||||
feedOwnerDid={feedInfo.creatorDid}
|
||||
|
@ -446,45 +435,6 @@ export function ProfileFeedScreenInner({
|
|||
)
|
||||
}
|
||||
|
||||
function NonPublicFeedMessage({rawError}: {rawError?: Error}) {
|
||||
const pal = usePalette('default')
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
pal.border,
|
||||
{
|
||||
padding: 18,
|
||||
borderTopWidth: 1,
|
||||
minHeight: Dimensions.get('window').height * 1.5,
|
||||
},
|
||||
]}>
|
||||
<View
|
||||
style={[
|
||||
pal.viewLight,
|
||||
{
|
||||
padding: 12,
|
||||
borderRadius: 8,
|
||||
gap: 12,
|
||||
},
|
||||
]}>
|
||||
<Text style={[pal.text]}>
|
||||
<Trans>
|
||||
Looks like this feed is only available to users with a Bluesky
|
||||
account. Please sign up or sign in to view this feed!
|
||||
</Trans>
|
||||
</Text>
|
||||
|
||||
{rawError?.message && (
|
||||
<Text style={pal.textLight}>
|
||||
<Trans>Message from server</Trans>: {rawError.message}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
interface FeedSectionProps {
|
||||
feed: FeedDescriptor
|
||||
headerHeight: number
|
||||
|
@ -519,7 +469,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
|
|||
<Feed
|
||||
enabled={isFocused}
|
||||
feed={feed}
|
||||
pollInterval={30e3}
|
||||
pollInterval={60e3}
|
||||
scrollElRef={scrollElRef}
|
||||
onHasNew={setHasNew}
|
||||
onScrolledDownChange={setIsScrolledDown}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue