summaryrefslogtreecommitdiffstats
path: root/models/issues/review.go
diff options
context:
space:
mode:
author6543 <m.huber@kithara.com>2023-12-20 16:19:58 +0100
committerGitHub <noreply@github.com>2023-12-20 16:19:58 +0100
commit2c48733afea30a5e25fc1a6b3054f0ae907f990b (patch)
tree518ec41c59a07489348c422430aeab8ac84f6219 /models/issues/review.go
parentFix the issue ref rendering for wiki (#28556) (diff)
downloadforgejo-2c48733afea30a5e25fc1a6b3054f0ae907f990b.tar.xz
forgejo-2c48733afea30a5e25fc1a6b3054f0ae907f990b.zip
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 https://github.com/go-gitea/gitea/pull/28544 (before refactoring)
Diffstat (limited to '')
-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 3db73a09eb..e2f65e369f 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -460,8 +460,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
@@ -475,13 +477,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
}