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/notification.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/notification.go')
-rw-r--r-- | models/notification.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/models/notification.go b/models/notification.go index 3c252d123d..db78558647 100644 --- a/models/notification.go +++ b/models/notification.go @@ -140,15 +140,16 @@ func CountNotifications(opts *FindNotificationOptions) (int64, error) { // CreateRepoTransferNotification creates notification for the user a repository was transferred to func CreateRepoTransferNotification(doer, newOwner *User, repo *Repository) 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() + var notify []*Notification if newOwner.IsOrganization() { - users, err := getUsersWhoCanCreateOrgRepo(sess, newOwner.ID) + users, err := getUsersWhoCanCreateOrgRepo(db.GetEngine(ctx), newOwner.ID) if err != nil || len(users) == 0 { return err } @@ -171,28 +172,28 @@ func CreateRepoTransferNotification(doer, newOwner *User, repo *Repository) erro }} } - if _, err := sess.InsertMulti(notify); err != nil { + if err := db.Insert(ctx, notify); err != nil { return err } - return sess.Commit() + return committer.Commit() } // CreateOrUpdateIssueNotifications creates an issue notification // for each watcher, or updates it if already exists // receiverID > 0 just send to reciver, else send to all watcher func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) 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() - if err := createOrUpdateIssueNotifications(sess, issueID, commentID, notificationAuthorID, receiverID); err != nil { + if err := createOrUpdateIssueNotifications(db.GetEngine(ctx), issueID, commentID, notificationAuthorID, receiverID); err != nil { return err } - return sess.Commit() + return committer.Commit() } func createOrUpdateIssueNotifications(e db.Engine, issueID, commentID, notificationAuthorID, receiverID int64) error { |