diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /models/issue_stopwatch.go | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r-- | models/issue_stopwatch.go | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index 81459ba446..5b9f5c402d 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -125,13 +125,9 @@ func StopwatchExists(userID, issueID int64) bool { } // HasUserStopwatch returns true if the user has a stopwatch -func HasUserStopwatch(userID int64) (exists bool, sw *Stopwatch, err error) { - return hasUserStopwatch(db.GetEngine(db.DefaultContext), userID) -} - -func hasUserStopwatch(e db.Engine, userID int64) (exists bool, sw *Stopwatch, err error) { +func HasUserStopwatch(ctx context.Context, userID int64) (exists bool, sw *Stopwatch, err error) { sw = new(Stopwatch) - exists, err = e. + exists, err = db.GetEngine(ctx). Where("user_id = ?", userID). Get(sw) return @@ -203,24 +199,23 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss }); err != nil { return err } - _, err = db.GetEngine(ctx).Delete(sw) + _, err = db.DeleteByBean(ctx, sw) return err } // CreateIssueStopwatch creates a stopwatch if not exist, otherwise return an error func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error { - e := db.GetEngine(ctx) if err := issue.LoadRepo(ctx); err != nil { return err } // if another stopwatch is running: stop it - exists, sw, err := hasUserStopwatch(e, user.ID) + exists, sw, err := HasUserStopwatch(ctx, user.ID) if err != nil { return err } if exists { - issue, err := getIssueByID(e, sw.IssueID) + issue, err := getIssueByID(ctx, sw.IssueID) if err != nil { return err } |