From b974785a55dfacc9a4c829d4ebc909e5a1b35645 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 6 Apr 2024 04:41:20 +0100 Subject: [PATCH 1/2] Include feed URL in feed events --- src/lib/statsig/events.ts | 2 ++ src/view/com/feeds/FeedPage.tsx | 33 ++++++++++++++------------- src/view/com/posts/Feed.tsx | 40 ++++++++++++++++++--------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/lib/statsig/events.ts b/src/lib/statsig/events.ts index 2de15b64ee..98d633194d 100644 --- a/src/lib/statsig/events.ts +++ b/src/lib/statsig/events.ts @@ -45,10 +45,12 @@ export type LogEvents = { 'onboarding:moderation:nextPressed': {} 'onboarding:finished:nextPressed': {} 'feed:endReached': { + feedUrl: string feedType: string itemCount: number } 'feed:refresh': { + feedUrl: string feedType: string reason: 'pull-to-refresh' | 'soft-reset' | 'load-latest' } diff --git a/src/view/com/feeds/FeedPage.tsx b/src/view/com/feeds/FeedPage.tsx index 2d0736b096..430e4980f0 100644 --- a/src/view/com/feeds/FeedPage.tsx +++ b/src/view/com/feeds/FeedPage.tsx @@ -1,28 +1,29 @@ import React from 'react' +import {useWindowDimensions, View} from 'react-native' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' import {useNavigation} from '@react-navigation/native' -import {useAnalytics} from 'lib/analytics/analytics' import {useQueryClient} from '@tanstack/react-query' + +import {getRootNavigation, getTabState, TabState} from '#/lib/routes/helpers' +import {logEvent} from '#/lib/statsig/statsig' +import {isNative} from '#/platform/detection' +import {listenSoftReset} from '#/state/events' import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed' -import {MainScrollProvider} from '../util/MainScrollProvider' -import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' -import {useSetMinimalShellMode} from '#/state/shell' import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed' +import {truncateAndInvalidate} from '#/state/queries/util' +import {useSession} from '#/state/session' +import {useSetMinimalShellMode} from '#/state/shell' +import {useComposerControls} from '#/state/shell/composer' +import {useAnalytics} from 'lib/analytics/analytics' +import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {ComposeIcon2} from 'lib/icons' import {s} from 'lib/styles' -import {View, useWindowDimensions} from 'react-native' -import {ListMethods} from '../util/List' import {Feed} from '../posts/Feed' import {FAB} from '../util/fab/FAB' +import {ListMethods} from '../util/List' import {LoadLatestBtn} from '../util/load-latest/LoadLatestBtn' -import {msg} from '@lingui/macro' -import {useLingui} from '@lingui/react' -import {useSession} from '#/state/session' -import {useComposerControls} from '#/state/shell/composer' -import {listenSoftReset} from '#/state/events' -import {truncateAndInvalidate} from '#/state/queries/util' -import {TabState, getTabState, getRootNavigation} from '#/lib/routes/helpers' -import {isNative} from '#/platform/detection' -import {logEvent} from '#/lib/statsig/statsig' +import {MainScrollProvider} from '../util/MainScrollProvider' const POLL_FREQ = 60e3 // 60sec @@ -71,6 +72,7 @@ export function FeedPage({ setHasNew(false) logEvent('feed:refresh', { feedType: feed.split('|')[0], + feedUrl: feed, reason: 'soft-reset', }) } @@ -96,6 +98,7 @@ export function FeedPage({ setHasNew(false) logEvent('feed:refresh', { feedType: feed.split('|')[0], + feedUrl: feed, reason: 'load-latest', }) }, [scrollToTop, feed, queryClient, setHasNew]) diff --git a/src/view/com/posts/Feed.tsx b/src/view/com/posts/Feed.tsx index 8afcce94f2..fb67d35c5c 100644 --- a/src/view/com/posts/Feed.tsx +++ b/src/view/com/posts/Feed.tsx @@ -8,32 +8,33 @@ import { View, ViewStyle, } from 'react-native' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' import {useQueryClient} from '@tanstack/react-query' -import {List, ListRef} from '../util/List' -import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder' -import {FeedErrorMessage} from './FeedErrorMessage' -import {FeedSlice} from './FeedSlice' -import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn' -import {useAnalytics} from 'lib/analytics/analytics' -import {useTheme} from 'lib/ThemeContext' + +import {FALLBACK_MARKER_POST} from '#/lib/api/feed/home' +import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' +import {isWeb} from '#/platform/detection' +import {listenPostCreated} from '#/state/events' +import {STALE} from '#/state/queries' import { - RQKEY, FeedDescriptor, FeedParams, - usePostFeedQuery, pollLatest, + RQKEY, + usePostFeedQuery, } from '#/state/queries/post-feed' -import {isWeb} from '#/platform/detection' -import {listenPostCreated} from '#/state/events' import {useSession} from '#/state/session' -import {STALE} from '#/state/queries' -import {msg} from '@lingui/macro' -import {useLingui} from '@lingui/react' -import {DiscoverFallbackHeader} from './DiscoverFallbackHeader' -import {FALLBACK_MARKER_POST} from '#/lib/api/feed/home' +import {useAnalytics} from 'lib/analytics/analytics' import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender' -import {logEvent} from '#/lib/statsig/statsig' +import {useTheme} from 'lib/ThemeContext' +import {List, ListRef} from '../util/List' +import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder' +import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn' +import {DiscoverFallbackHeader} from './DiscoverFallbackHeader' +import {FeedErrorMessage} from './FeedErrorMessage' +import {FeedSlice} from './FeedSlice' const LOADING_ITEM = {_reactKey: '__loading__'} const EMPTY_FEED_ITEM = {_reactKey: '__empty__'} @@ -217,6 +218,7 @@ let Feed = ({ track('Feed:onRefresh') logEvent('feed:refresh', { feedType: feedType, + feedUrl: feed, reason: 'pull-to-refresh', }) setIsPTRing(true) @@ -227,13 +229,14 @@ let Feed = ({ logger.error('Failed to refresh posts feed', {message: err}) } setIsPTRing(false) - }, [refetch, track, setIsPTRing, onHasNew, feedType]) + }, [refetch, track, setIsPTRing, onHasNew, feed, feedType]) const onEndReached = React.useCallback(async () => { if (isFetching || !hasNextPage || isError) return logEvent('feed:endReached', { feedType: feedType, + feedUrl: feed, itemCount: feedItems.length, }) track('Feed:onEndReached') @@ -248,6 +251,7 @@ let Feed = ({ isError, fetchNextPage, track, + feed, feedType, feedItems.length, ]) From 849957aef9a9f1fc02b1d90f2ef06cd17b8d805f Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 6 Apr 2024 05:04:38 +0100 Subject: [PATCH 2/2] [Experiment] Turn off polling interval for Discover --- src/view/com/feeds/FeedPage.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/view/com/feeds/FeedPage.tsx b/src/view/com/feeds/FeedPage.tsx index 430e4980f0..25c7e1006d 100644 --- a/src/view/com/feeds/FeedPage.tsx +++ b/src/view/com/feeds/FeedPage.tsx @@ -6,7 +6,7 @@ import {useNavigation} from '@react-navigation/native' import {useQueryClient} from '@tanstack/react-query' import {getRootNavigation, getTabState, TabState} from '#/lib/routes/helpers' -import {logEvent} from '#/lib/statsig/statsig' +import {logEvent, useGate} from '#/lib/statsig/statsig' import {isNative} from '#/platform/detection' import {listenSoftReset} from '#/state/events' import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed' @@ -103,6 +103,17 @@ export function FeedPage({ }) }, [scrollToTop, feed, queryClient, setHasNew]) + let feedPollInterval + if ( + useGate('disable_poll_on_discover') && + feed === // Discover + 'feedgen|at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot' + ) { + feedPollInterval = undefined + } else { + feedPollInterval = POLL_FREQ + } + return ( @@ -111,7 +122,7 @@ export function FeedPage({ enabled={isPageFocused} feed={feed} feedParams={feedParams} - pollInterval={POLL_FREQ} + pollInterval={feedPollInterval} disablePoll={hasNew} scrollElRef={scrollElRef} onScrolledDownChange={setIsScrolledDown}