Reduce polling (#2465)
* Move profile and preference polling to polls-on-foreground * Refetch prefs on feeds screen refresh since polling no longer occurs * Reduce notifications polling by 50% if there's already an unread * Disable feed polling if we know we have content * Disable the hard refresh after 1 hour in case it's the cause of the random feed refresh bug * Fix types
This commit is contained in:
parent
0442dcc1a0
commit
7ab4be6f7d
10 changed files with 79 additions and 14 deletions
|
@ -174,6 +174,7 @@ export function FeedPage({
|
|||
feed={feed}
|
||||
feedParams={feedParams}
|
||||
pollInterval={POLL_FREQ}
|
||||
disablePoll={hasNew}
|
||||
scrollElRef={scrollElRef}
|
||||
onScrolledDownChange={setIsScrolledDown}
|
||||
onHasNew={setHasNew}
|
||||
|
|
|
@ -36,7 +36,8 @@ const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
|
|||
const ERROR_ITEM = {_reactKey: '__error__'}
|
||||
const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'}
|
||||
|
||||
const REFRESH_AFTER = STALE.HOURS.ONE
|
||||
// DISABLED need to check if this is causing random feed refreshes -prf
|
||||
// const REFRESH_AFTER = STALE.HOURS.ONE
|
||||
const CHECK_LATEST_AFTER = STALE.SECONDS.THIRTY
|
||||
|
||||
let Feed = ({
|
||||
|
@ -46,6 +47,7 @@ let Feed = ({
|
|||
style,
|
||||
enabled,
|
||||
pollInterval,
|
||||
disablePoll,
|
||||
scrollElRef,
|
||||
onScrolledDownChange,
|
||||
onHasNew,
|
||||
|
@ -63,6 +65,7 @@ let Feed = ({
|
|||
style?: StyleProp<ViewStyle>
|
||||
enabled?: boolean
|
||||
pollInterval?: number
|
||||
disablePoll?: boolean
|
||||
scrollElRef?: ListRef
|
||||
onHasNew?: (v: boolean) => void
|
||||
onScrolledDownChange?: (isScrolledDown: boolean) => void
|
||||
|
@ -107,7 +110,7 @@ let Feed = ({
|
|||
)
|
||||
|
||||
const checkForNew = React.useCallback(async () => {
|
||||
if (!data?.pages[0] || isFetching || !onHasNew || !enabled) {
|
||||
if (!data?.pages[0] || isFetching || !onHasNew || !enabled || disablePoll) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
|
@ -117,7 +120,7 @@ let Feed = ({
|
|||
} catch (e) {
|
||||
logger.error('Poll latest failed', {feed, error: String(e)})
|
||||
}
|
||||
}, [feed, data, isFetching, onHasNew, enabled])
|
||||
}, [feed, data, isFetching, onHasNew, enabled, disablePoll])
|
||||
|
||||
const myDid = currentAccount?.did || ''
|
||||
const onPostCreated = React.useCallback(() => {
|
||||
|
@ -146,11 +149,12 @@ let Feed = ({
|
|||
React.useEffect(() => {
|
||||
if (enabled) {
|
||||
const timeSinceFirstLoad = Date.now() - lastFetchRef.current
|
||||
if (timeSinceFirstLoad > REFRESH_AFTER) {
|
||||
// DISABLED need to check if this is causing random feed refreshes -prf
|
||||
/*if (timeSinceFirstLoad > REFRESH_AFTER) {
|
||||
// do a full refresh
|
||||
scrollElRef?.current?.scrollToOffset({offset: 0, animated: false})
|
||||
queryClient.resetQueries({queryKey: RQKEY(feed)})
|
||||
} else if (
|
||||
} else*/ if (
|
||||
timeSinceFirstLoad > CHECK_LATEST_AFTER &&
|
||||
checkForNewRef.current
|
||||
) {
|
||||
|
|
|
@ -97,6 +97,7 @@ export function FeedsScreen(_props: Props) {
|
|||
data: preferences,
|
||||
isLoading: isPreferencesLoading,
|
||||
error: preferencesError,
|
||||
refetch: refetchPreferences,
|
||||
} = usePreferencesQuery()
|
||||
const {
|
||||
data: popularFeeds,
|
||||
|
@ -151,9 +152,12 @@ export function FeedsScreen(_props: Props) {
|
|||
}, [query, debouncedSearch])
|
||||
const onPullToRefresh = React.useCallback(async () => {
|
||||
setIsPTR(true)
|
||||
await refetchPopularFeeds()
|
||||
await Promise.all([
|
||||
refetchPreferences().catch(_e => undefined),
|
||||
refetchPopularFeeds().catch(_e => undefined),
|
||||
])
|
||||
setIsPTR(false)
|
||||
}, [setIsPTR, refetchPopularFeeds])
|
||||
}, [setIsPTR, refetchPreferences, refetchPopularFeeds])
|
||||
const onEndReached = React.useCallback(() => {
|
||||
if (
|
||||
isPopularFeedsFetching ||
|
||||
|
|
|
@ -490,6 +490,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
|
|||
enabled={isFocused}
|
||||
feed={feed}
|
||||
pollInterval={60e3}
|
||||
disablePoll={hasNew}
|
||||
scrollElRef={scrollElRef}
|
||||
onHasNew={setHasNew}
|
||||
onScrolledDownChange={setIsScrolledDown}
|
||||
|
|
|
@ -646,6 +646,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
|
|||
enabled={isFocused}
|
||||
feed={feed}
|
||||
pollInterval={60e3}
|
||||
disablePoll={hasNew}
|
||||
scrollElRef={scrollElRef}
|
||||
onHasNew={setHasNew}
|
||||
onScrolledDownChange={setIsScrolledDown}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue