#6576: Fix reaction-fetch infinite retries when no results are returned

This commit is contained in:
infinite-persistence 2021-07-20 15:37:09 +08:00
commit 1eada066ff
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
6 changed files with 32 additions and 21 deletions

View file

@ -11,12 +11,13 @@ import { doToast } from 'redux/actions/notifications';
import { doSetPlayingUri } from 'redux/actions/content'; import { doSetPlayingUri } from 'redux/actions/content';
import { selectUserVerifiedEmail } from 'redux/selectors/user'; import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { selectLinkedCommentAncestors, makeSelectOthersReactionsForComment } from 'redux/selectors/comments'; import { selectLinkedCommentAncestors, makeSelectOthersReactionsForComment } from 'redux/selectors/comments';
import { selectActiveChannelId, selectActiveChannelClaim } from 'redux/selectors/app'; import { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectPlayingUri } from 'redux/selectors/content'; import { selectPlayingUri } from 'redux/selectors/content';
import Comment from './view'; import Comment from './view';
const select = (state, props) => { const select = (state, props) => {
const activeChannelId = selectActiveChannelId(state); const activeChannelClaim = selectActiveChannelClaim(state);
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
const reactionKey = activeChannelId ? `${props.commentId}:${activeChannelId}` : props.commentId; const reactionKey = activeChannelId ? `${props.commentId}:${activeChannelId}` : props.commentId;
return { return {
@ -25,7 +26,7 @@ const select = (state, props) => {
channelIsBlocked: props.authorUri && makeSelectChannelIsMuted(props.authorUri)(state), channelIsBlocked: props.authorUri && makeSelectChannelIsMuted(props.authorUri)(state),
commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true, commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
othersReacts: makeSelectOthersReactionsForComment(reactionKey)(state), othersReacts: makeSelectOthersReactionsForComment(reactionKey)(state),
activeChannelClaim: selectActiveChannelClaim(state), activeChannelClaim,
myChannels: selectMyChannelClaims(state), myChannels: selectMyChannelClaims(state),
playingUri: selectPlayingUri(state), playingUri: selectPlayingUri(state),
stakedLevel: makeSelectStakedLevelForChannelUri(props.authorUri)(state), stakedLevel: makeSelectStakedLevelForChannelUri(props.authorUri)(state),

View file

@ -4,10 +4,11 @@ import { makeSelectClaimIsMine, makeSelectClaimForUri } from 'lbry-redux';
import { doToast } from 'redux/actions/notifications'; import { doToast } from 'redux/actions/notifications';
import { makeSelectMyReactionsForComment, makeSelectOthersReactionsForComment } from 'redux/selectors/comments'; import { makeSelectMyReactionsForComment, makeSelectOthersReactionsForComment } from 'redux/selectors/comments';
import { doCommentReact } from 'redux/actions/comments'; import { doCommentReact } from 'redux/actions/comments';
import { selectActiveChannelId } from 'redux/selectors/app'; import { selectActiveChannelClaim } from 'redux/selectors/app';
const select = (state, props) => { const select = (state, props) => {
const activeChannelId = selectActiveChannelId(state); const activeChannelClaim = selectActiveChannelClaim(state);
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
const reactionKey = activeChannelId ? `${props.commentId}:${activeChannelId}` : props.commentId; const reactionKey = activeChannelId ? `${props.commentId}:${activeChannelId}` : props.commentId;
return { return {

View file

@ -13,10 +13,11 @@ import {
} from 'redux/selectors/comments'; } from 'redux/selectors/comments';
import { doCommentReset, doCommentList, doCommentById, doCommentReactList } from 'redux/actions/comments'; import { doCommentReset, doCommentList, doCommentById, doCommentReactList } from 'redux/actions/comments';
import { selectUserVerifiedEmail } from 'redux/selectors/user'; import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { selectActiveChannelId } from 'redux/selectors/app'; import { selectActiveChannelClaim } from 'redux/selectors/app';
import CommentsList from './view'; import CommentsList from './view';
const select = (state, props) => { const select = (state, props) => {
const activeChannelClaim = selectActiveChannelClaim(state);
return { return {
myChannels: selectMyChannelClaims(state), myChannels: selectMyChannelClaims(state),
allCommentIds: makeSelectCommentIdsForUri(props.uri)(state), allCommentIds: makeSelectCommentIdsForUri(props.uri)(state),
@ -31,7 +32,7 @@ const select = (state, props) => {
fetchingChannels: selectFetchingMyChannels(state), fetchingChannels: selectFetchingMyChannels(state),
myReactsByCommentId: selectMyReactionsByCommentId(state), myReactsByCommentId: selectMyReactionsByCommentId(state),
othersReactsById: selectOthersReactsById(state), othersReactsById: selectOthersReactsById(state),
activeChannelId: selectActiveChannelId(state), activeChannelId: activeChannelClaim && activeChannelClaim.claim_id,
}; };
}; };

View file

@ -76,8 +76,6 @@ 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 [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
const [readyToDisplayComments, setReadyToDisplayComments] = React.useState( const [readyToDisplayComments, setReadyToDisplayComments] = React.useState(
@ -138,9 +136,7 @@ function CommentList(props: Props) {
}); });
} }
if (idsForReactionFetch.length !== 0 && reactionFetchCount < 500) { if (idsForReactionFetch.length !== 0) {
setReactionFetchCount(reactionFetchCount + 1);
fetchReacts(idsForReactionFetch) fetchReacts(idsForReactionFetch)
.then(() => { .then(() => {
setReadyToDisplayComments(true); setReadyToDisplayComments(true);
@ -158,8 +154,6 @@ function CommentList(props: Props) {
activeChannelId, activeChannelId,
fetchingChannels, fetchingChannels,
isFetchingReacts, isFetchingReacts,
reactionFetchCount,
setReactionFetchCount,
]); ]);
// Scroll to linked-comment // Scroll to linked-comment

View file

@ -236,9 +236,10 @@ export function doCommentReactList(commentIds: Array<string>) {
dispatch({ dispatch({
type: ACTIONS.COMMENT_REACTION_LIST_COMPLETED, type: ACTIONS.COMMENT_REACTION_LIST_COMPLETED,
data: { data: {
myReactions: myReactions || {}, myReactions,
othersReactions, othersReactions,
channelId: activeChannelClaim ? activeChannelClaim.claim_id : undefined, channelId: activeChannelClaim ? activeChannelClaim.claim_id : undefined,
commentIds,
}, },
}); });
}) })
@ -379,7 +380,7 @@ export function doCommentCreate(
livestream?: boolean = false, livestream?: boolean = false,
txid?: string, txid?: string,
payment_intent_id?: string, payment_intent_id?: string,
environment?: string, environment?: string
) { ) {
return async (dispatch: Dispatch, getState: GetState) => { return async (dispatch: Dispatch, getState: GetState) => {
const state = getState(); const state = getState();

View file

@ -182,12 +182,15 @@ export default handleActions(
}, },
[ACTIONS.COMMENT_REACTION_LIST_COMPLETED]: (state: CommentsState, action: any): CommentsState => { [ACTIONS.COMMENT_REACTION_LIST_COMPLETED]: (state: CommentsState, action: any): CommentsState => {
const { myReactions, othersReactions, channelId } = action.data; const { myReactions, othersReactions, channelId, commentIds } = action.data;
const myReacts = Object.assign({}, state.myReactsByCommentId); const myReacts = Object.assign({}, state.myReactsByCommentId);
const othersReacts = Object.assign({}, state.othersReactsByCommentId); const othersReacts = Object.assign({}, state.othersReactsByCommentId);
if (myReactions) { const myReactionsEntries = myReactions ? Object.entries(myReactions) : [];
Object.entries(myReactions).forEach(([commentId, reactions]) => { const othersReactionsEntries = othersReactions ? Object.entries(othersReactions) : [];
if (myReactionsEntries.length > 0) {
myReactionsEntries.forEach(([commentId, reactions]) => {
const key = channelId ? `${commentId}:${channelId}` : commentId; const key = channelId ? `${commentId}:${channelId}` : commentId;
myReacts[key] = Object.entries(reactions).reduce((acc, [name, count]) => { myReacts[key] = Object.entries(reactions).reduce((acc, [name, count]) => {
if (count === 1) { if (count === 1) {
@ -196,13 +199,23 @@ export default handleActions(
return acc; return acc;
}, []); }, []);
}); });
} else {
commentIds.forEach((commentId) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
myReacts[key] = [];
});
} }
if (othersReactions) { if (othersReactionsEntries.length > 0) {
Object.entries(othersReactions).forEach(([commentId, reactions]) => { othersReactionsEntries.forEach(([commentId, reactions]) => {
const key = channelId ? `${commentId}:${channelId}` : commentId; const key = channelId ? `${commentId}:${channelId}` : commentId;
othersReacts[key] = reactions; othersReacts[key] = reactions;
}); });
} else {
commentIds.forEach((commentId) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
othersReacts[key] = {};
});
} }
return { return {