From 47d39b20d32c2076013e80ed63a574a7a7c1efff Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Sat, 17 Jul 2021 13:53:10 +0800 Subject: [PATCH] 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. --- ui/component/commentsList/view.jsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ui/component/commentsList/view.jsx b/ui/component/commentsList/view.jsx index e3380cad7..668512bcc 100644 --- a/ui/component/commentsList/view.jsx +++ b/ui/component/commentsList/view.jsx @@ -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