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
This commit is contained in:
parent
d81e31ad78
commit
fd7d83ace6
232 changed files with 1463 additions and 2108 deletions
|
@ -5,6 +5,7 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
@ -51,15 +52,15 @@ type TranslatableMessage struct {
|
|||
|
||||
// LoadRepo loads repository of the task
|
||||
func (task *Task) LoadRepo() error {
|
||||
return task.loadRepo(db.GetEngine(db.DefaultContext))
|
||||
return task.loadRepo(db.DefaultContext)
|
||||
}
|
||||
|
||||
func (task *Task) loadRepo(e db.Engine) error {
|
||||
func (task *Task) loadRepo(ctx context.Context) error {
|
||||
if task.Repo != nil {
|
||||
return nil
|
||||
}
|
||||
var repo repo_model.Repository
|
||||
has, err := e.ID(task.RepoID).Get(&repo)
|
||||
has, err := db.GetEngine(ctx).ID(task.RepoID).Get(&repo)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
|
@ -233,12 +234,7 @@ func FindTasks(opts FindTaskOptions) ([]*Task, error) {
|
|||
|
||||
// CreateTask creates a task on database
|
||||
func CreateTask(task *Task) error {
|
||||
return createTask(db.GetEngine(db.DefaultContext), task)
|
||||
}
|
||||
|
||||
func createTask(e db.Engine, task *Task) error {
|
||||
_, err := e.Insert(task)
|
||||
return err
|
||||
return db.Insert(db.DefaultContext, task)
|
||||
}
|
||||
|
||||
// FinishMigrateTask updates database when migrate task finished
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue