Skip to content

#1721: fetch issue comments count once per PR instead of once per review#1844

Open
morphqdd wants to merge 2 commits into
zerocracy:masterfrom
morphqdd:1721-paginate-code-reviews
Open

#1721: fetch issue comments count once per PR instead of once per review#1844
morphqdd wants to merge 2 commits into
zerocracy:masterfrom
morphqdd:1721-paginate-code-reviews

Conversation

@morphqdd

Copy link
Copy Markdown
Contributor

Closes #1721.

judges/code-was-reviewed/code-was-reviewed.rb fetched Fbe.octo.issue_comments(repo, f.issue).count inside the reviews.each loop, once per review — but the result doesn't depend on the review at all (it's a property of the PR, not the individual review). For a PR with N new reviews in one judge cycle, this refetched the exact same issue-comments count N times instead of once, on top of the necessarily-per-review pull_request_review_comments call.

Fix: hoisted the fetch into a memoized count local (count ||= ...) computed once per PR, reused for every review's n.comments assignment. Fbe.if_absent's next if n.nil? guard still gates whether the fetch happens at all (already-recorded reviews skip it, same as before) — only the redundant repeat for multiple new reviews on the same PR is eliminated.

Added test_fetches_issue_comments_once_for_multiple_reviews, stubbing a PR with 2 new reviews and asserting the issues/60/comments endpoint is hit exactly once (assert_requested(..., times: 1)) instead of twice.

Note: I wasn't able to run the test suite locally due to an unrelated native-gem/Ruby-version mismatch in my environment (openssl gem compiled against a stale libruby). I verified the change via ruby -c (syntax OK) and rubocop (no new violations vs. the pre-existing baseline — confirmed by diffing rubocop output before/after on the unmodified file) and by tracing through the logic by hand.

@morphqdd

Copy link
Copy Markdown
Contributor Author

@yegor256, please take a look when you have a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

judges/code-was-reviewed.rb code reviews not paginated

1 participant