Unverified Commit ffb0e96f authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub

Merge pull request #5664 from LLK/revert-5660-revert-5630-reduce-reply-requests

Reduce reply requests, for real this time I promise
parents 3958d9df ccc07d3c
......@@ -69,8 +69,10 @@ const getTopLevelComments = (id, offset, ownerUsername, isAdmin, token) => (disp
}
dispatch(setFetchStatus('comments', Status.FETCHED));
dispatch(setComments(body));
dispatch(getReplies(id, body.map(comment => comment.id), 0, ownerUsername, isAdmin, token));
const commentsWithReplies = body.filter(comment => comment.reply_count > 0);
if (commentsWithReplies.length > 0) {
dispatch(getReplies(id, commentsWithReplies.map(comment => comment.id), 0, ownerUsername, isAdmin, token));
}
// If we loaded a full page of comments, assume there are more to load.
// This will be wrong (1 / COMMENT_LIMIT) of the time, but does not require
// any more server query complexity, so seems worth it. In the case of a project with
......@@ -105,7 +107,9 @@ const getCommentById = (projectId, commentId, ownerUsername, isAdmin, token) =>
// If the comment is not a reply, show it as top level and load replies
dispatch(setFetchStatus('comments', Status.FETCHED));
dispatch(setComments([body]));
if (body.reply_count > 0) {
dispatch(getReplies(projectId, [body.id], 0, ownerUsername, isAdmin, token));
}
});
});
......
......@@ -90,7 +90,10 @@ const getTopLevelComments = () => ((dispatch, getState) => {
}
dispatch(setFetchStatus('comments', Status.FETCHED));
dispatch(setComments(body));
dispatch(getReplies(body.map(comment => comment.id), 0));
const commentsWithReplies = body.filter(comment => comment.reply_count > 0);
if (commentsWithReplies.length > 0) {
dispatch(getReplies(commentsWithReplies.map(comment => comment.id), 0));
}
// If we loaded a full page of comments, assume there are more to load.
// This will be wrong (1 / COMMENT_LIMIT) of the time, but does not require
......@@ -130,7 +133,9 @@ const getCommentById = commentId => ((dispatch, getState) => {
// If the comment is not a reply, show it as top level and load replies
dispatch(setFetchStatus('comments', Status.FETCHED));
dispatch(setComments([body]));
if (body.reply_count > 0) {
dispatch(getReplies(body.id, 0));
}
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment