Experiment: hardstop reaction-fetch at 500
(Hypothetical max comment of 3000) / (10 comments per page) = 300. Cap at 500 to stop runnaway loops.
This commit is contained in:
parent
84a2a74c8c
commit
cd32fb71c7
1 changed files with 6 additions and 11 deletions
|
@ -76,7 +76,7 @@ function CommentList(props: Props) {
|
||||||
const [page, setPage] = React.useState(0);
|
const [page, setPage] = React.useState(0);
|
||||||
const totalFetchedComments = allCommentIds ? allCommentIds.length : 0;
|
const totalFetchedComments = allCommentIds ? allCommentIds.length : 0;
|
||||||
|
|
||||||
const [noReactsOccurrence, setNoReactsOccurrence] = React.useState(0);
|
const [reactionFetchCount, setReactionFetchCount] = React.useState(0);
|
||||||
|
|
||||||
// Display comments immediately if not fetching reactions
|
// Display comments immediately if not fetching reactions
|
||||||
// If not, wait to show comments until reactions are fetched
|
// If not, wait to show comments until reactions are fetched
|
||||||
|
@ -131,13 +131,6 @@ function CommentList(props: Props) {
|
||||||
|
|
||||||
if (!othersReactsById || !myReactsByCommentId) {
|
if (!othersReactsById || !myReactsByCommentId) {
|
||||||
idsForReactionFetch = allCommentIds;
|
idsForReactionFetch = allCommentIds;
|
||||||
|
|
||||||
if (noReactsOccurrence > 3) {
|
|
||||||
// Still no reactions fetched after 3 attempts. Let's stop for now.
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
setNoReactsOccurrence(noReactsOccurrence + 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
idsForReactionFetch = allCommentIds.filter((commentId) => {
|
idsForReactionFetch = allCommentIds.filter((commentId) => {
|
||||||
const key = activeChannelId ? `${commentId}:${activeChannelId}` : commentId;
|
const key = activeChannelId ? `${commentId}:${activeChannelId}` : commentId;
|
||||||
|
@ -145,7 +138,9 @@ function CommentList(props: Props) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idsForReactionFetch.length !== 0) {
|
if (idsForReactionFetch.length !== 0 && reactionFetchCount < 500) {
|
||||||
|
setReactionFetchCount(reactionFetchCount + 1);
|
||||||
|
|
||||||
fetchReacts(idsForReactionFetch)
|
fetchReacts(idsForReactionFetch)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setReadyToDisplayComments(true);
|
setReadyToDisplayComments(true);
|
||||||
|
@ -163,8 +158,8 @@ function CommentList(props: Props) {
|
||||||
activeChannelId,
|
activeChannelId,
|
||||||
fetchingChannels,
|
fetchingChannels,
|
||||||
isFetchingReacts,
|
isFetchingReacts,
|
||||||
noReactsOccurrence,
|
reactionFetchCount,
|
||||||
setNoReactsOccurrence,
|
setReactionFetchCount,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Scroll to linked-comment
|
// Scroll to linked-comment
|
||||||
|
|
Loading…
Reference in a new issue