Add gate to increase post-feed page size (#5473)
* Add gate to increase post-feed page size * Exclude Discover * Remove exception * Clarify intent * Let gate cache
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
export type Gate =
|
export type Gate =
|
||||||
// Keep this alphabetic please.
|
// Keep this alphabetic please.
|
||||||
'debug_show_feedcontext' | 'suggested_feeds_interstitial'
|
| 'debug_show_feedcontext'
|
||||||
|
| 'post_feed_lang_window'
|
||||||
|
| 'suggested_feeds_interstitial'
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {FeedTuner, FeedTunerFn} from '#/lib/api/feed-manip'
|
|||||||
import {DISCOVER_FEED_URI} from '#/lib/constants'
|
import {DISCOVER_FEED_URI} from '#/lib/constants'
|
||||||
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
|
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
|
||||||
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
||||||
|
import {useGate} from '#/lib/statsig/statsig'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const'
|
import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const'
|
||||||
@@ -109,13 +110,19 @@ export interface FeedPage {
|
|||||||
fetchedAt: number
|
fetchedAt: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
/**
|
||||||
|
* The minimum number of posts we want in a single "page" of results. Since we
|
||||||
|
* filter out unwanted content, we may fetch more than this number to ensure
|
||||||
|
* that we get _at least_ this number.
|
||||||
|
*/
|
||||||
|
const MIN_POSTS = 30
|
||||||
|
|
||||||
export function usePostFeedQuery(
|
export function usePostFeedQuery(
|
||||||
feedDesc: FeedDescriptor,
|
feedDesc: FeedDescriptor,
|
||||||
params?: FeedParams,
|
params?: FeedParams,
|
||||||
opts?: {enabled?: boolean; ignoreFilterFor?: string},
|
opts?: {enabled?: boolean; ignoreFilterFor?: string},
|
||||||
) {
|
) {
|
||||||
|
const gate = useGate()
|
||||||
const feedTuners = useFeedTuners(feedDesc)
|
const feedTuners = useFeedTuners(feedDesc)
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const {data: preferences} = usePreferencesQuery()
|
const {data: preferences} = usePreferencesQuery()
|
||||||
@@ -135,6 +142,13 @@ export function usePostFeedQuery(
|
|||||||
} | null>(null)
|
} | null>(null)
|
||||||
const isDiscover = feedDesc.includes(DISCOVER_FEED_URI)
|
const isDiscover = feedDesc.includes(DISCOVER_FEED_URI)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of posts to fetch in a single request. Because we filter
|
||||||
|
* unwanted content, we may over-fetch here to try and fill pages by
|
||||||
|
* `MIN_POSTS`.
|
||||||
|
*/
|
||||||
|
const fetchLimit = gate('post_feed_lang_window') ? 100 : MIN_POSTS
|
||||||
|
|
||||||
// Make sure this doesn't invalidate unless really needed.
|
// Make sure this doesn't invalidate unless really needed.
|
||||||
const selectArgs = React.useMemo(
|
const selectArgs = React.useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -175,7 +189,7 @@ export function usePostFeedQuery(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await api.fetch({cursor, limit: PAGE_SIZE})
|
const res = await api.fetch({cursor, limit: fetchLimit})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a public view, we need to check if posts fail moderation.
|
* If this is a public view, we need to check if posts fail moderation.
|
||||||
@@ -373,13 +387,13 @@ export function usePostFeedQuery(
|
|||||||
// Now track how many items we really want, and fetch more if needed.
|
// Now track how many items we really want, and fetch more if needed.
|
||||||
if (isLoading || isRefetching) {
|
if (isLoading || isRefetching) {
|
||||||
// During the initial fetch, we want to get an entire page's worth of items.
|
// During the initial fetch, we want to get an entire page's worth of items.
|
||||||
wantedItemCount.current = PAGE_SIZE
|
wantedItemCount.current = MIN_POSTS
|
||||||
} else if (isFetchingNextPage) {
|
} else if (isFetchingNextPage) {
|
||||||
if (itemCount > wantedItemCount.current) {
|
if (itemCount > wantedItemCount.current) {
|
||||||
// We have more items than wantedItemCount, so wantedItemCount must be out of date.
|
// We have more items than wantedItemCount, so wantedItemCount must be out of date.
|
||||||
// Some other code must have called fetchNextPage(), for example, from onEndReached.
|
// Some other code must have called fetchNextPage(), for example, from onEndReached.
|
||||||
// Adjust the wantedItemCount to reflect that we want one more full page of items.
|
// Adjust the wantedItemCount to reflect that we want one more full page of items.
|
||||||
wantedItemCount.current = itemCount + PAGE_SIZE
|
wantedItemCount.current = itemCount + MIN_POSTS
|
||||||
}
|
}
|
||||||
} else if (hasNextPage) {
|
} else if (hasNextPage) {
|
||||||
// At this point we're not fetching anymore, so it's time to make a decision.
|
// At this point we're not fetching anymore, so it's time to make a decision.
|
||||||
|
|||||||
Reference in New Issue
Block a user