Skip to content

Commit bdba85b

Browse files
author
Cory Todd
committed
Constraint FindReviews with condition
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>
1 parent 970d85e commit bdba85b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

models/issues/pull_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,4 @@ func TestGetApprovers(t *testing.T) {
336336
approvers := pr.GetApprovers()
337337
expected := "Reviewed-by: User Five <user5@example.com>\nReviewed-by: User Six <user6@example.com>\n"
338338
assert.EqualValues(t, expected, approvers)
339-
}
339+
}

models/issues/review.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,16 @@ func (opts *FindReviewOptions) toCond() builder.Cond {
266266
// FindReviews returns reviews passing FindReviewOptions
267267
func FindReviews(ctx context.Context, opts FindReviewOptions) ([]*Review, error) {
268268
reviews := make([]*Review, 0, 10)
269-
sess := db.GetEngine(ctx).Where(opts.toCond())
269+
cond := opts.toCond()
270+
sess := db.GetEngine(ctx).Where(cond)
270271
if opts.Page > 0 {
271272
sess = db.SetSessionPagination(sess, &opts)
272273
}
273274
if opts.LatestOnly {
274275
sess.In("id", builder.
275276
Select("max ( id ) ").
276277
From("review").
278+
Where(cond).
277279
GroupBy("reviewer_id"))
278280
}
279281
return reviews, sess.

0 commit comments

Comments
 (0)