diff options
author | zeripath <art27@cantab.net> | 2021-09-23 16:45:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 23:45:36 +0800 |
commit | 9302eba971611601c3ebf6024e22a11c63f4e151 (patch) | |
tree | a3e5583986161ef62e7affc694098279ecf2217d /models/issue_watch.go | |
parent | b22be7f594401d7bd81196750456ce52185bd391 (diff) | |
download | gitea-9302eba971611601c3ebf6024e22a11c63f4e151.tar.gz gitea-9302eba971611601c3ebf6024e22a11c63f4e151.zip |
DBContext is just a Context (#17100)
* DBContext is just a Context
This PR removes some of the specialness from the DBContext and makes it context
This allows us to simplify the GetEngine code to wrap around any context in future
and means that we can change our loadRepo(e Engine) functions to simply take contexts.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* fix unit tests
Signed-off-by: Andrew Thornton <art27@cantab.net>
* another place that needs to set the initial context
Signed-off-by: Andrew Thornton <art27@cantab.net>
* avoid race
Signed-off-by: Andrew Thornton <art27@cantab.net>
* change attachment error
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/issue_watch.go')
-rw-r--r-- | models/issue_watch.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/models/issue_watch.go b/models/issue_watch.go index dd693f82f5..cc1edcba1b 100644 --- a/models/issue_watch.go +++ b/models/issue_watch.go @@ -28,7 +28,7 @@ type IssueWatchList []*IssueWatch // CreateOrUpdateIssueWatch set watching for a user and issue func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error { - iw, exists, err := getIssueWatch(db.DefaultContext().Engine(), userID, issueID) + iw, exists, err := getIssueWatch(db.GetEngine(db.DefaultContext), userID, issueID) if err != nil { return err } @@ -40,13 +40,13 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error { IsWatching: isWatching, } - if _, err := db.DefaultContext().Engine().Insert(iw); err != nil { + if _, err := db.GetEngine(db.DefaultContext).Insert(iw); err != nil { return err } } else { iw.IsWatching = isWatching - if _, err := db.DefaultContext().Engine().ID(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil { + if _, err := db.GetEngine(db.DefaultContext).ID(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil { return err } } @@ -56,7 +56,7 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error { // GetIssueWatch returns all IssueWatch objects from db by user and issue // the current Web-UI need iw object for watchers AND explicit non-watchers func GetIssueWatch(userID, issueID int64) (iw *IssueWatch, exists bool, err error) { - return getIssueWatch(db.DefaultContext().Engine(), userID, issueID) + return getIssueWatch(db.GetEngine(db.DefaultContext), userID, issueID) } // Return watcher AND explicit non-watcher if entry in db exist @@ -72,14 +72,14 @@ func getIssueWatch(e db.Engine, userID, issueID int64) (iw *IssueWatch, exists b // CheckIssueWatch check if an user is watching an issue // it takes participants and repo watch into account func CheckIssueWatch(user *User, issue *Issue) (bool, error) { - iw, exist, err := getIssueWatch(db.DefaultContext().Engine(), user.ID, issue.ID) + iw, exist, err := getIssueWatch(db.GetEngine(db.DefaultContext), user.ID, issue.ID) if err != nil { return false, err } if exist { return iw.IsWatching, nil } - w, err := getWatch(db.DefaultContext().Engine(), user.ID, issue.RepoID) + w, err := getWatch(db.GetEngine(db.DefaultContext), user.ID, issue.RepoID) if err != nil { return false, err } @@ -90,7 +90,7 @@ func CheckIssueWatch(user *User, issue *Issue) (bool, error) { // but avoids joining with `user` for performance reasons // User permissions must be verified elsewhere if required func GetIssueWatchersIDs(issueID int64, watching bool) ([]int64, error) { - return getIssueWatchersIDs(db.DefaultContext().Engine(), issueID, watching) + return getIssueWatchersIDs(db.GetEngine(db.DefaultContext), issueID, watching) } func getIssueWatchersIDs(e db.Engine, issueID int64, watching bool) ([]int64, error) { @@ -104,7 +104,7 @@ func getIssueWatchersIDs(e db.Engine, issueID int64, watching bool) ([]int64, er // GetIssueWatchers returns watchers/unwatchers of a given issue func GetIssueWatchers(issueID int64, listOptions ListOptions) (IssueWatchList, error) { - return getIssueWatchers(db.DefaultContext().Engine(), issueID, listOptions) + return getIssueWatchers(db.GetEngine(db.DefaultContext), issueID, listOptions) } func getIssueWatchers(e db.Engine, issueID int64, listOptions ListOptions) (IssueWatchList, error) { |