-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duplicate Reviewed-by trailers #24796
Fix duplicate Reviewed-by trailers #24796
Conversation
A test would be nice here. |
05bac74
to
3ea36d0
Compare
Is it ready? |
Yes, was waiting for the tests to pass before I removed the draft state thanks for the reminder! |
3ea36d0
to
c8e8fea
Compare
The merge conflict has been resolved so this is ready again. |
models/issues/review.go
Outdated
sess.In("id", builder. | ||
Select("max ( id ) "). | ||
From("review"). | ||
GroupBy("reviewer_id")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more "where" condition for this query?
For a instance with 100,000 reviews, this "IN" query will group these 100,000 reviews for each FindReviews call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue_id condition is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I wasn't sure about this one since IssueID will not always be provided. I think re-using the outer condition on where on the subquery should be okay?
Enable deduplication of unofficial reviews. When pull requests are configured to include all approvers, not just official ones, in the default merge messages it was possible to generate duplicated Reviewed-by lines for a single person. fixes go-gitea#24795 Signed-off-by: Cory Todd <cory.todd@canonical.com>
Not all SQL dialects will work with Distinct so use a subquery grouping instead. Add 3 reviews to the test data to simulate the scenario being fixed by this patch. - One reviewer submitting 2 reviews. Only the latest should be returned. - One reviewer submitting 1 review. This is the oldest review and should still be the first approver. Omitting LatestOnly should preserve existing behavior as it is used by the REST API. Signed-off-by: Cory Todd <cory.todd@canonical.com>
On the LatestOnly subquery, re-use the outter condition to avoid always grouping by all reviews in the database. Signed-off-by: Cory Todd <cory.todd@canonical.com>
97fff06
to
bdba85b
Compare
Fixed more conflicts. |
models/issues/review.go
Outdated
@@ -243,6 +243,7 @@ type FindReviewOptions struct { | |||
IssueID int64 | |||
ReviewerID int64 | |||
OfficialOnly bool | |||
LatestOnly bool // Latest per-reviewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading the code again, I think it's better to add a FindLatestReviews
, instead of adding LatestOnly
to FindReviewOptions.
The reason is, the newly added LatestOnly
is not respected by toCond
, but FindReviewOptions
is shared by FindReviewOptions
and CountReviewOptions
. So, if LatestOnly=true, FindReviewOptions and CountReviewOptions behave differently, it would cause bugs or confuse developers in the future.
If we introduce a FindLatestReviews
, then everything is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good point, thanks for the feedback. I've made the requested revisions.
Do not create future sources for bugs by introducing the LatestOnly field. Use an explicit function instead. Signed-off-by: Cory Todd <cory.todd@canonical.com>
Should we backport this? |
* upstream/main: [skip ci] Updated licenses and gitignores Add `WithPullRequest` for `actionsNotifier` (go-gitea#25144) [skip ci] Updated translations via Crowdin [skip ci] Updated translations via Crowdin Update github.com/google/go-github to v53 (go-gitea#25157) Fix bug for code search if code is disabled (go-gitea#25173) Minor arc-green color tweaks (go-gitea#25175) Fix duplicate Reviewed-by trailers (go-gitea#24796) Fix go-gitea#25133 (go-gitea#25162) Fix mobile navbar and misc cleanups (go-gitea#25134) Button and color enhancements (go-gitea#24989) Fix setup-go actions (go-gitea#25167) # Conflicts: # templates/base/head_navbar.tmpl
Enable deduplication of unofficial reviews. When pull requests are configured to include all approvers, not just official ones, in the default merge messages it was possible to generate duplicated Reviewed-by lines for a single person. Add an option to find only distinct reviews for a given query.
fixes #24795