Paginate fetchComments and keep recent comments on truncation#536
Merged
Paginate fetchComments and keep recent comments on truncation#536
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/source/github.go">
<violation number="1" location="internal/source/github.go:429">
P2: Quadratic slice prepend: `append([]string{...}, parts...)` copies the entire `parts` slice on every iteration, resulting in O(n²) allocations. Consider appending in reverse order and reversing at the end, or pre-allocating with index placement.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
ce8f03c to
2705688
Compare
fetchComments previously made a single HTTP request, returning at most 100 comments. On busy issues the most recent comments — including trigger and exclude commands — were silently dropped. Apply the same pagination loop used by fetchAllIssues (up to maxPages). concatCommentBodies truncated from the front (oldest kept), compounding the data loss. Reverse the truncation direction so the most recent comments are preserved within the maxCommentBytes budget. Replaces the O(n²) prepend pattern with an O(n) append-then-reverse approach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2705688 to
1564de7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind bug
What this PR does / why we need it:
fetchCommentspreviously made a single HTTP request, returning at most 100 comments per issue. On busy issues (>100 comments), the most recent comments — includingTriggerCommentandExcludeCommentcommands — were silently dropped. This PR:fetchCommentsusing the same loop pattern asfetchAllIssues(up tomaxPagespages), via a newfetchCommentsPagehelper that mirrorsfetchIssuesPage.concatCommentBodiestruncation order so that when the total exceedsmaxCommentBytes, older comments are dropped from the front and the most recent comments are preserved. Uses an efficient O(n) append-then-reverse approach.Which issue(s) this PR is related to:
Fixes #528
Special notes for your reviewer:
The pagination infrastructure (
parseNextLink,maxPages) already existed for issues. This PR reuses it for comments with the same pattern. No new constants or types were introduced.Does this PR introduce a user-facing change?