Stop fetching reacts if failed for 3 times

Not sure if this will ever occur, but technically possible from the code point of view. Try adding this to see if it stops the spikes in `reaction.list` calls.
This commit is contained in:
infinite-persistence 2021-07-17 13:53:10 +08:00
parent 9c05239b04
commit 47d39b20d3
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -76,6 +76,8 @@ function CommentList(props: Props) {
const [page, setPage] = React.useState(0);
const totalFetchedComments = allCommentIds ? allCommentIds.length : 0;
const [noReactsOccurrence, setNoReactsOccurrence] = React.useState(0);
// Display comments immediately if not fetching reactions
// If not, wait to show comments until reactions are fetched
const [readyToDisplayComments, setReadyToDisplayComments] = React.useState(
@ -129,6 +131,13 @@ function CommentList(props: Props) {
if (!othersReactsById || !myReactsByCommentId) {
idsForReactionFetch = allCommentIds;
if (noReactsOccurrence > 3) {
// Still no reactions fetched after 3 attempts. Let's stop for now.
return;
} else {
setNoReactsOccurrence(noReactsOccurrence + 1);
}
} else {
idsForReactionFetch = allCommentIds.filter((commentId) => {
const key = activeChannelId ? `${commentId}:${activeChannelId}` : commentId;
@ -154,6 +163,8 @@ function CommentList(props: Props) {
activeChannelId,
fetchingChannels,
isFetchingReacts,
noReactsOccurrence,
setNoReactsOccurrence,
]);
// Scroll to linked-comment