aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_tracked_time.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_tracked_time.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_tracked_time.go')
-rw-r--r--models/issue_tracked_time.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go
index 77b44df1ee..d024c6896f 100644
--- a/models/issue_tracked_time.go
+++ b/models/issue_tracked_time.go
@@ -40,7 +40,7 @@ func (t *TrackedTime) AfterLoad() {
// LoadAttributes load Issue, User
func (t *TrackedTime) LoadAttributes() (err error) {
- return t.loadAttributes(db.DefaultContext().Engine())
+ return t.loadAttributes(db.GetEngine(db.DefaultContext))
}
func (t *TrackedTime) loadAttributes(e db.Engine) (err error) {
@@ -131,12 +131,12 @@ func getTrackedTimes(e db.Engine, options *FindTrackedTimesOptions) (trackedTime
// GetTrackedTimes returns all tracked times that fit to the given options.
func GetTrackedTimes(opts *FindTrackedTimesOptions) (TrackedTimeList, error) {
- return getTrackedTimes(db.DefaultContext().Engine(), opts)
+ return getTrackedTimes(db.GetEngine(db.DefaultContext), opts)
}
// CountTrackedTimes returns count of tracked times that fit to the given options.
func CountTrackedTimes(opts *FindTrackedTimesOptions) (int64, error) {
- sess := db.DefaultContext().Engine().Where(opts.toCond())
+ sess := db.GetEngine(db.DefaultContext).Where(opts.toCond())
if opts.RepositoryID > 0 || opts.MilestoneID > 0 {
sess = sess.Join("INNER", "issue", "issue.id = tracked_time.issue_id")
}
@@ -149,12 +149,12 @@ func getTrackedSeconds(e db.Engine, opts FindTrackedTimesOptions) (trackedSecond
// GetTrackedSeconds return sum of seconds
func GetTrackedSeconds(opts FindTrackedTimesOptions) (int64, error) {
- return getTrackedSeconds(db.DefaultContext().Engine(), opts)
+ return getTrackedSeconds(db.GetEngine(db.DefaultContext), opts)
}
// AddTime will add the given time (in seconds) to the issue
func AddTime(user *User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -230,7 +230,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*User]string, error) {
// DeleteIssueUserTimes deletes times for issue
func DeleteIssueUserTimes(issue *Issue, user *User) error {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -268,7 +268,7 @@ func DeleteIssueUserTimes(issue *Issue, user *User) error {
// DeleteTime delete a specific Time
func DeleteTime(t *TrackedTime) error {
- sess := db.DefaultContext().NewSession()
+ sess := db.NewSession(db.DefaultContext)
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -318,7 +318,7 @@ func deleteTime(e db.Engine, t *TrackedTime) error {
// GetTrackedTimeByID returns raw TrackedTime without loading attributes by id
func GetTrackedTimeByID(id int64) (*TrackedTime, error) {
time := new(TrackedTime)
- has, err := db.DefaultContext().Engine().ID(id).Get(time)
+ has, err := db.GetEngine(db.DefaultContext).ID(id).Get(time)
if err != nil {
return nil, err
} else if !has {