mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user