Skip to content

Commit

Permalink
Only fallback to Discover if Following is first pinned (#4146)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored May 21, 2024
1 parent d6625c2 commit b89e4de
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/state/queries/post-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import {HomeFeedAPI} from '#/lib/api/feed/home'
import {aggregateUserInterests} from '#/lib/api/feed/utils'
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
import {useGate} from '#/lib/statsig/statsig'
import {logger} from '#/logger'
import {STALE} from '#/state/queries'
import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const'
Expand Down Expand Up @@ -111,14 +110,18 @@ export function usePostFeedQuery(
const enabled =
opts?.enabled !== false && Boolean(moderationOpts) && Boolean(preferences)
const userInterests = aggregateUserInterests(preferences)
const followingPinnedIndex =
preferences?.savedFeeds?.findIndex(
f => f.pinned && f.value === 'following',
) ?? -1
const enableFollowingToDiscoverFallback = followingPinnedIndex === 0
const {getAgent} = useAgent()
const lastRun = useRef<{
data: InfiniteData<FeedPageUnselected>
args: typeof selectArgs
result: InfiniteData<FeedPage>
} | null>(null)
const lastPageCountRef = useRef(0)
const gate = useGate()

// Make sure this doesn't invalidate unless really needed.
const selectArgs = React.useMemo(
Expand Down Expand Up @@ -150,15 +153,11 @@ export function usePostFeedQuery(
feedDesc,
feedParams: params || {},
feedTuners,
userInterests, // Not in the query key because they don't change.
getAgent,
useBaseFollowingFeed: gate(
'reduced_onboarding_and_home_algo_v2',
{
// If you're not already in this experiment, we don't want to expose you to it now.
dangerouslyDisableExposureLogging: true,
},
),
// Not in the query key because they don't change:
userInterests,
// Not in the query key. Reacting to it switching isn't important:
enableFollowingToDiscoverFallback,
}),
cursor: undefined,
}
Expand Down Expand Up @@ -392,14 +391,14 @@ function createApi({
feedTuners,
userInterests,
getAgent,
useBaseFollowingFeed,
enableFollowingToDiscoverFallback,
}: {
feedDesc: FeedDescriptor
feedParams: FeedParams
feedTuners: FeedTunerFn[]
userInterests?: string
getAgent: () => BskyAgent
useBaseFollowingFeed: boolean
enableFollowingToDiscoverFallback: boolean
}) {
if (feedDesc === 'following') {
if (feedParams.mergeFeedEnabled) {
Expand All @@ -410,10 +409,10 @@ function createApi({
userInterests,
})
} else {
if (useBaseFollowingFeed) {
return new FollowingFeedAPI({getAgent})
} else {
if (enableFollowingToDiscoverFallback) {
return new HomeFeedAPI({getAgent, userInterests})
} else {
return new FollowingFeedAPI({getAgent})
}
}
} else if (feedDesc.startsWith('author')) {
Expand Down

0 comments on commit b89e4de

Please sign in to comment.