summaryrefslogtreecommitdiffstats
path: root/models/issue_stopwatch.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-09-23 16:45:36 +0100
committerGitHub <noreply@github.com>2021-09-23 23:45:36 +0800
commit9302eba971611601c3ebf6024e22a11c63f4e151 (patch)
treea3e5583986161ef62e7affc694098279ecf2217d /models/issue_stopwatch.go
parentb22be7f594401d7bd81196750456ce52185bd391 (diff)
downloadgitea-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_stopwatch.go')
-rw-r--r--models/issue_stopwatch.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go
index 1e8cf4c6a6..157658e182 100644
--- a/models/issue_stopwatch.go
+++ b/models/issue_stopwatch.go
@@ -48,7 +48,7 @@ func getStopwatch(e db.Engine, userID, issueID int64) (sw *Stopwatch, exists boo
// GetUserStopwatches return list of all stopwatches of a user
func GetUserStopwatches(userID int64, listOptions ListOptions) ([]*Stopwatch, error) {
sws := make([]*Stopwatch, 0, 8)
- sess := db.DefaultContext().Engine().Where("stopwatch.user_id = ?", userID)
+ sess := db.GetEngine(db.DefaultContext).Where("stopwatch.user_id = ?", userID)
if listOptions.Page != 0 {
sess = setSessionPagination(sess, &listOptions)
}
@@ -62,18 +62,18 @@ func GetUserStopwatches(userID int64, listOptions ListOptions) ([]*Stopwatch, er
// CountUserStopwatches return count of all stopwatches of a user
func CountUserStopwatches(userID int64) (int64, error) {
- return db.DefaultContext().Engine().Where("user_id = ?", userID).Count(&Stopwatch{})
+ return db.GetEngine(db.DefaultContext).Where("user_id = ?", userID).Count(&Stopwatch{})
}
// StopwatchExists returns true if the stopwatch exists
func StopwatchExists(userID, issueID int64) bool {
- _, exists, _ := getStopwatch(db.DefaultContext().Engine(), userID, issueID)
+ _, exists, _ := getStopwatch(db.GetEngine(db.DefaultContext), userID, issueID)
return exists
}
// HasUserStopwatch returns true if the user has a stopwatch
func HasUserStopwatch(userID int64) (exists bool, sw *Stopwatch, err error) {
- return hasUserStopwatch(db.DefaultContext().Engine(), userID)
+ return hasUserStopwatch(db.GetEngine(db.DefaultContext), userID)
}
func hasUserStopwatch(e db.Engine, userID int64) (exists bool, sw *Stopwatch, err error) {
@@ -86,7 +86,7 @@ func hasUserStopwatch(e db.Engine, userID int64) (exists bool, sw *Stopwatch, er
// CreateOrStopIssueStopwatch will create or remove a stopwatch and will log it into issue's timeline.
func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
@@ -175,7 +175,7 @@ func createOrStopIssueStopwatch(e *xorm.Session, user *User, issue *Issue) error
// CancelStopwatch removes the given stopwatch and logs it into issue's timeline.
func CancelStopwatch(user *User, issue *Issue) error {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
return err