summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2023-12-20 23:55:08 +0800
committerGitHub <noreply@github.com>2023-12-20 16:55:08 +0100
commit16263af9715afcfa249cf43157b2ae9b4d4765f4 (patch)
tree8f94fc54a7f635922af7a4283fa62ff5e6f35f02
parentf096635622f117f7552e98d9ab3625369015e6ed (diff)
downloadgitea-16263af9715afcfa249cf43157b2ae9b4d4765f4.tar.gz
gitea-16263af9715afcfa249cf43157b2ae9b4d4765f4.zip
Fix inperformant query on retrifing review from database. (#28552) (#28562)
Backport #28552 by @6543 can we please PLEAS PLEASE only use raw SQL statements if it is relay needed!!! source is https://github.com/go-gitea/gitea/pull/28544 (before refactoring) Co-authored-by: 6543 <m.huber@kithara.com>
-rw-r--r--models/issues/review.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/models/issues/review.go b/models/issues/review.go
index 257b86de5b..eae8c20e97 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -461,8 +461,10 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*Review, error) {
review := new(Review)
- 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 (?, ?, ?))",
- issueID, userID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
+ has, err := db.GetEngine(ctx).Where(
+ builder.In("type", ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
+ And(builder.Eq{"issue_id": issueID, "reviewer_id": userID, "original_author_id": 0})).
+ Desc("id").
Get(review)
if err != nil {
return nil, err
@@ -476,13 +478,13 @@ func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*R
}
// GetTeamReviewerByIssueIDAndTeamID get the latest review request of reviewer team for a pull request
-func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int64) (review *Review, err error) {
- review = new(Review)
+func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int64) (*Review, error) {
+ review := new(Review)
- var has bool
- 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 = ?)",
- issueID, teamID).
- Get(review); err != nil {
+ has, err := db.GetEngine(ctx).Where(builder.Eq{"issue_id": issueID, "reviewer_team_id": teamID}).
+ Desc("id").
+ Get(review)
+ if err != nil {
return nil, err
}