Grab-bag of post-feed improvements (#2140)
* Sanity check against cases where empty pages may occur * Use the mergefeed as an emergency fallback to an empty feed * Check for new posts on focuszio/stable
parent
52a0cb8fac
commit
040ce03215
|
@ -29,7 +29,7 @@ export class MergeFeedAPI implements FeedAPI {
|
||||||
this.feedCursor = 0
|
this.feedCursor = 0
|
||||||
this.itemCursor = 0
|
this.itemCursor = 0
|
||||||
this.sampleCursor = 0
|
this.sampleCursor = 0
|
||||||
if (this.params.mergeFeedEnabled && this.params.mergeFeedSources) {
|
if (this.params.mergeFeedSources) {
|
||||||
this.customFeeds = shuffle(
|
this.customFeeds = shuffle(
|
||||||
this.params.mergeFeedSources.map(
|
this.params.mergeFeedSources.map(
|
||||||
feedUri => new MergeFeedSource_Custom(feedUri, this.feedTuners),
|
feedUri => new MergeFeedSource_Custom(feedUri, this.feedTuners),
|
||||||
|
@ -108,7 +108,10 @@ export class MergeFeedAPI implements FeedAPI {
|
||||||
|
|
||||||
// this condition establishes the frequency that custom feeds are woven into follows
|
// this condition establishes the frequency that custom feeds are woven into follows
|
||||||
const shouldSample =
|
const shouldSample =
|
||||||
i >= 15 && candidateFeeds.length >= 2 && (i % 4 === 0 || i % 5 === 0)
|
this.params.mergeFeedEnabled &&
|
||||||
|
i >= 15 &&
|
||||||
|
candidateFeeds.length >= 2 &&
|
||||||
|
(i % 4 === 0 || i % 5 === 0)
|
||||||
|
|
||||||
if (!canSample && !hasFollows) {
|
if (!canSample && !hasFollows) {
|
||||||
// no data available
|
// no data available
|
||||||
|
|
|
@ -91,11 +91,15 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
const {isFetching, hasNextPage, data} = query
|
const {isFetching, hasNextPage, data} = query
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
|
let numEmpties = 0
|
||||||
for (const page of data?.pages || []) {
|
for (const page of data?.pages || []) {
|
||||||
|
if (!page.items.length) {
|
||||||
|
numEmpties++
|
||||||
|
}
|
||||||
count += page.items.length
|
count += page.items.length
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFetching && hasNextPage && count < PAGE_SIZE) {
|
if (!isFetching && hasNextPage && count < PAGE_SIZE && numEmpties < 3) {
|
||||||
query.fetchNextPage()
|
query.fetchNextPage()
|
||||||
}
|
}
|
||||||
}, [query])
|
}, [query])
|
||||||
|
|
|
@ -217,13 +217,17 @@ export function usePostFeedQuery(
|
||||||
const {isFetching, hasNextPage, data} = query
|
const {isFetching, hasNextPage, data} = query
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
|
let numEmpties = 0
|
||||||
for (const page of data?.pages || []) {
|
for (const page of data?.pages || []) {
|
||||||
|
if (page.slices.length === 0) {
|
||||||
|
numEmpties++
|
||||||
|
}
|
||||||
for (const slice of page.slices) {
|
for (const slice of page.slices) {
|
||||||
count += slice.items.length
|
count += slice.items.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFetching && hasNextPage && count < PAGE_SIZE) {
|
if (!isFetching && hasNextPage && count < PAGE_SIZE && numEmpties < 3) {
|
||||||
query.fetchNextPage()
|
query.fetchNextPage()
|
||||||
}
|
}
|
||||||
}, [query])
|
}, [query])
|
||||||
|
|
|
@ -132,13 +132,20 @@ let Feed = ({
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// we store the interval handler in a ref to avoid needless
|
// we store the interval handler in a ref to avoid needless
|
||||||
// reassignments of the interval
|
// reassignments in other effects
|
||||||
checkForNewRef.current = checkForNew
|
checkForNewRef.current = checkForNew
|
||||||
}, [checkForNew])
|
}, [checkForNew])
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (enabled && checkForNewRef.current) {
|
||||||
|
// check for new on enable (aka on focus)
|
||||||
|
checkForNewRef.current()
|
||||||
|
}
|
||||||
|
}, [enabled])
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!pollInterval) {
|
if (!pollInterval) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// check for new on interval
|
||||||
const i = setInterval(() => checkForNewRef.current?.(), pollInterval)
|
const i = setInterval(() => checkForNewRef.current?.(), pollInterval)
|
||||||
return () => clearInterval(i)
|
return () => clearInterval(i)
|
||||||
}, [pollInterval])
|
}, [pollInterval])
|
||||||
|
|
|
@ -175,7 +175,7 @@ function HomeScreenReady({
|
||||||
key="1"
|
key="1"
|
||||||
testID="followingFeedPage"
|
testID="followingFeedPage"
|
||||||
isPageFocused={selectedPageIndex === 0}
|
isPageFocused={selectedPageIndex === 0}
|
||||||
feed={homeFeedParams.mergeFeedEnabled ? 'home' : 'following'}
|
feed="home"
|
||||||
feedParams={homeFeedParams}
|
feedParams={homeFeedParams}
|
||||||
renderEmptyState={renderFollowingEmptyState}
|
renderEmptyState={renderFollowingEmptyState}
|
||||||
renderEndOfFeed={FollowingEndOfFeed}
|
renderEndOfFeed={FollowingEndOfFeed}
|
||||||
|
|
Loading…
Reference in New Issue