Skip to content

Commit 2c48733

Browse files
authored
Fix inperformant query on retrifing review from database. (#28552)
can we please PLEAS PLEASE only use raw SQL statements if it is relay needed!!! source is #28544 (before refactoring)
1 parent e4a24d6 commit 2c48733

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

models/issues/review.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,10 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
460460
func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*Review, error) {
461461
review := new(Review)
462462

463-
has, err := db.GetEngine(ctx).SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_id = ? AND original_author_id = 0 AND type in (?, ?, ?))",
464-
issueID, userID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
463+
has, err := db.GetEngine(ctx).Where(
464+
builder.In("type", ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
465+
And(builder.Eq{"issue_id": issueID, "reviewer_id": userID, "original_author_id": 0})).
466+
Desc("id").
465467
Get(review)
466468
if err != nil {
467469
return nil, err
@@ -475,13 +477,13 @@ func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*R
475477
}
476478

477479
// GetTeamReviewerByIssueIDAndTeamID get the latest review request of reviewer team for a pull request
478-
func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int64) (review *Review, err error) {
479-
review = new(Review)
480+
func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int64) (*Review, error) {
481+
review := new(Review)
480482

481-
var has bool
482-
if has, err = db.GetEngine(ctx).SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = ?)",
483-
issueID, teamID).
484-
Get(review); err != nil {
483+
has, err := db.GetEngine(ctx).Where(builder.Eq{"issue_id": issueID, "reviewer_team_id": teamID}).
484+
Desc("id").
485+
Get(review)
486+
if err != nil {
485487
return nil, err
486488
}
487489

0 commit comments

Comments
 (0)