1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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>
This commit is contained in:
zeripath
2021-09-23 16:45:36 +01:00
committed by GitHub
parent b22be7f594
commit 9302eba971
129 changed files with 1112 additions and 1022 deletions

View File

@@ -5,6 +5,7 @@
package models
import (
"context"
"fmt"
"code.gitea.io/gitea/models/db"
@@ -43,7 +44,7 @@ func (archiver *RepoArchiver) LoadRepo() (*Repository, error) {
}
var repo Repository
has, err := db.DefaultContext().Engine().ID(archiver.RepoID).Get(&repo)
has, err := db.GetEngine(db.DefaultContext).ID(archiver.RepoID).Get(&repo)
if err != nil {
return nil, err
}
@@ -61,9 +62,9 @@ func (archiver *RepoArchiver) RelativePath() (string, error) {
}
// GetRepoArchiver get an archiver
func GetRepoArchiver(ctx *db.Context, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) {
func GetRepoArchiver(ctx context.Context, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) {
var archiver RepoArchiver
has, err := ctx.Engine().Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver)
has, err := db.GetEngine(ctx).Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver)
if err != nil {
return nil, err
}
@@ -74,19 +75,19 @@ func GetRepoArchiver(ctx *db.Context, repoID int64, tp git.ArchiveType, commitID
}
// AddRepoArchiver adds an archiver
func AddRepoArchiver(ctx *db.Context, archiver *RepoArchiver) error {
_, err := ctx.Engine().Insert(archiver)
func AddRepoArchiver(ctx context.Context, archiver *RepoArchiver) error {
_, err := db.GetEngine(ctx).Insert(archiver)
return err
}
// UpdateRepoArchiverStatus updates archiver's status
func UpdateRepoArchiverStatus(ctx *db.Context, archiver *RepoArchiver) error {
_, err := ctx.Engine().ID(archiver.ID).Cols("status").Update(archiver)
func UpdateRepoArchiverStatus(ctx context.Context, archiver *RepoArchiver) error {
_, err := db.GetEngine(ctx).ID(archiver.ID).Cols("status").Update(archiver)
return err
}
// DeleteAllRepoArchives deletes all repo archives records
func DeleteAllRepoArchives() error {
_, err := db.DefaultContext().Engine().Where("1=1").Delete(new(RepoArchiver))
_, err := db.GetEngine(db.DefaultContext).Where("1=1").Delete(new(RepoArchiver))
return err
}