loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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)

authored by

6543 and committed by
GitHub
2c48733a e4a24d67

+10 -8
+10 -8
models/issues/review.go
··· 460 460 func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*Review, error) { 461 461 review := new(Review) 462 462 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"). 465 467 Get(review) 466 468 if err != nil { 467 469 return nil, err ··· 475 477 } 476 478 477 479 // 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) 480 482 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 { 485 487 return nil, err 486 488 } 487 489