diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-21 23:41:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 23:41:00 +0800 |
commit | d710af6669654f27f02b69d7ef1ba563e7d58a90 (patch) | |
tree | 9727f468a570106293dc90beb70035180bbb7e8e /models/review.go | |
parent | 0add627182388ac63fd04b94cdf912fb87fd0326 (diff) | |
download | gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.tar.gz gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.zip |
Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface
* Fix bug
* Some improvements
* Fix bug
* Fix test
* Use XXXBean instead of XXXExample
Diffstat (limited to 'models/review.go')
-rw-r--r-- | models/review.go | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/models/review.go b/models/review.go index 62172bac01..00906c7a27 100644 --- a/models/review.go +++ b/models/review.go @@ -472,11 +472,7 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, comm func GetReviewersByIssueID(issueID int64) ([]*Review, error) { reviews := make([]*Review, 0, 10) - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { - return nil, err - } + sess := db.GetEngine(db.DefaultContext) // Get latest review of each reviewer, sorted in order they were made if err := sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = 0 AND type in (?, ?, ?) AND dismissed = ? AND original_author_id = 0 GROUP BY issue_id, reviewer_id) ORDER BY review.updated_unix ASC", @@ -590,12 +586,12 @@ func DismissReview(review *Review, isDismiss bool) (err error) { // InsertReviews inserts review and review comments func InsertReviews(reviews []*Review) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + sess := db.GetEngine(ctx) for _, review := range reviews { if _, err := sess.NoAutoTime().Insert(review); err != nil { @@ -627,7 +623,7 @@ func InsertReviews(reviews []*Review) error { } } - return sess.Commit() + return committer.Commit() } // AddReviewRequest add a review request from one reviewer @@ -920,12 +916,12 @@ func CanMarkConversation(issue *Issue, doer *User) (permResult bool, err error) // DeleteReview delete a review and it's code comments func DeleteReview(r *Review) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + sess := db.GetEngine(ctx) if r.ID == 0 { return fmt.Errorf("review is not allowed to be 0") @@ -959,7 +955,7 @@ func DeleteReview(r *Review) error { return err } - return sess.Commit() + return committer.Commit() } // GetCodeCommentsCount return count of CodeComments a Review has |