diff options
author | zeripath <art27@cantab.net> | 2021-09-23 16:45:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 23:45:36 +0800 |
commit | 9302eba971611601c3ebf6024e22a11c63f4e151 (patch) | |
tree | a3e5583986161ef62e7affc694098279ecf2217d /models/u2f.go | |
parent | b22be7f594401d7bd81196750456ce52185bd391 (diff) | |
download | gitea-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/u2f.go')
-rw-r--r-- | models/u2f.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/models/u2f.go b/models/u2f.go index 66943f8dd2..17b8295626 100644 --- a/models/u2f.go +++ b/models/u2f.go @@ -45,7 +45,7 @@ func (reg *U2FRegistration) updateCounter(e db.Engine) error { // UpdateCounter will update the database value of counter func (reg *U2FRegistration) UpdateCounter() error { - return reg.updateCounter(db.DefaultContext().Engine()) + return reg.updateCounter(db.GetEngine(db.DefaultContext)) } // U2FRegistrationList is a list of *U2FRegistration @@ -73,7 +73,7 @@ func getU2FRegistrationsByUID(e db.Engine, uid int64) (U2FRegistrationList, erro // GetU2FRegistrationByID returns U2F registration by id func GetU2FRegistrationByID(id int64) (*U2FRegistration, error) { - return getU2FRegistrationByID(db.DefaultContext().Engine(), id) + return getU2FRegistrationByID(db.GetEngine(db.DefaultContext), id) } func getU2FRegistrationByID(e db.Engine, id int64) (*U2FRegistration, error) { @@ -88,7 +88,7 @@ func getU2FRegistrationByID(e db.Engine, id int64) (*U2FRegistration, error) { // GetU2FRegistrationsByUID returns all U2F registrations of the given user func GetU2FRegistrationsByUID(uid int64) (U2FRegistrationList, error) { - return getU2FRegistrationsByUID(db.DefaultContext().Engine(), uid) + return getU2FRegistrationsByUID(db.GetEngine(db.DefaultContext), uid) } func createRegistration(e db.Engine, user *User, name string, reg *u2f.Registration) (*U2FRegistration, error) { @@ -111,12 +111,12 @@ func createRegistration(e db.Engine, user *User, name string, reg *u2f.Registrat // CreateRegistration will create a new U2FRegistration from the given Registration func CreateRegistration(user *User, name string, reg *u2f.Registration) (*U2FRegistration, error) { - return createRegistration(db.DefaultContext().Engine(), user, name, reg) + return createRegistration(db.GetEngine(db.DefaultContext), user, name, reg) } // DeleteRegistration will delete U2FRegistration func DeleteRegistration(reg *U2FRegistration) error { - return deleteRegistration(db.DefaultContext().Engine(), reg) + return deleteRegistration(db.GetEngine(db.DefaultContext), reg) } func deleteRegistration(e db.Engine, reg *U2FRegistration) error { |