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:
@@ -62,32 +62,32 @@ func (m *PushMirror) GetRemoteName() string {
|
||||
|
||||
// InsertPushMirror inserts a push-mirror to database
|
||||
func InsertPushMirror(m *PushMirror) error {
|
||||
_, err := db.DefaultContext().Engine().Insert(m)
|
||||
_, err := db.GetEngine(db.DefaultContext).Insert(m)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdatePushMirror updates the push-mirror
|
||||
func UpdatePushMirror(m *PushMirror) error {
|
||||
_, err := db.DefaultContext().Engine().ID(m.ID).AllCols().Update(m)
|
||||
_, err := db.GetEngine(db.DefaultContext).ID(m.ID).AllCols().Update(m)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeletePushMirrorByID deletes a push-mirrors by ID
|
||||
func DeletePushMirrorByID(ID int64) error {
|
||||
_, err := db.DefaultContext().Engine().ID(ID).Delete(&PushMirror{})
|
||||
_, err := db.GetEngine(db.DefaultContext).ID(ID).Delete(&PushMirror{})
|
||||
return err
|
||||
}
|
||||
|
||||
// DeletePushMirrorsByRepoID deletes all push-mirrors by repoID
|
||||
func DeletePushMirrorsByRepoID(repoID int64) error {
|
||||
_, err := db.DefaultContext().Engine().Delete(&PushMirror{RepoID: repoID})
|
||||
_, err := db.GetEngine(db.DefaultContext).Delete(&PushMirror{RepoID: repoID})
|
||||
return err
|
||||
}
|
||||
|
||||
// GetPushMirrorByID returns push-mirror information.
|
||||
func GetPushMirrorByID(ID int64) (*PushMirror, error) {
|
||||
m := &PushMirror{}
|
||||
has, err := db.DefaultContext().Engine().ID(ID).Get(m)
|
||||
has, err := db.GetEngine(db.DefaultContext).ID(ID).Get(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
@@ -99,12 +99,12 @@ func GetPushMirrorByID(ID int64) (*PushMirror, error) {
|
||||
// GetPushMirrorsByRepoID returns push-mirror information of a repository.
|
||||
func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) {
|
||||
mirrors := make([]*PushMirror, 0, 10)
|
||||
return mirrors, db.DefaultContext().Engine().Where("repo_id=?", repoID).Find(&mirrors)
|
||||
return mirrors, db.GetEngine(db.DefaultContext).Where("repo_id=?", repoID).Find(&mirrors)
|
||||
}
|
||||
|
||||
// PushMirrorsIterate iterates all push-mirror repositories.
|
||||
func PushMirrorsIterate(f func(idx int, bean interface{}) error) error {
|
||||
return db.DefaultContext().Engine().
|
||||
return db.GetEngine(db.DefaultContext).
|
||||
Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
|
||||
And("`interval` != 0").
|
||||
Iterate(new(PushMirror), f)
|
||||
|
Reference in New Issue
Block a user