Description
When running gh issue view --comments, the command first fetches the issue details including the first 100 comments. Then, it calls preloadIssueComments to fetch any additional comments if they exist.
Currently, preloadIssueComments in pkg/cmd/issue/view/http.go has a logic flaw:
- It checks if
issue.Comments.PageInfo.HasNextPage is true.
- If it is false (meaning all comments were already fetched in the first request), it clears
issue.Comments.Nodes and proceeds to re-fetch them anyway!
if issue.Comments.PageInfo.HasNextPage {
variables["endCursor"] = githubv4.String(issue.Comments.PageInfo.EndCursor)
} else {
issue.Comments.Nodes = issue.Comments.Nodes[0:0] // This clears existing comments!
}
This is inefficient as it makes a redundant second request even when all comments are already available.
Expected Behavior
If issue.Comments.PageInfo.HasNextPage is false, preloadIssueComments should return immediately.
If it is true, it should start fetching from the endCursor and append to the existing nodes.
Proposed Fix
Modify preloadIssueComments to return early if no more pages exist, and avoid clearing existing nodes when more pages do exist.
Description
When running
gh issue view --comments, the command first fetches the issue details including the first 100 comments. Then, it callspreloadIssueCommentsto fetch any additional comments if they exist.Currently,
preloadIssueCommentsinpkg/cmd/issue/view/http.gohas a logic flaw:issue.Comments.PageInfo.HasNextPageis true.issue.Comments.Nodesand proceeds to re-fetch them anyway!This is inefficient as it makes a redundant second request even when all comments are already available.
Expected Behavior
If
issue.Comments.PageInfo.HasNextPageis false,preloadIssueCommentsshould return immediately.If it is true, it should start fetching from the
endCursorand append to the existing nodes.Proposed Fix
Modify
preloadIssueCommentsto return early if no more pages exist, and avoid clearing existing nodes when more pages do exist.