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/user_openid.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/user_openid.go')
-rw-r--r-- | models/user_openid.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/models/user_openid.go b/models/user_openid.go index 4844b68c29..17a58536a2 100644 --- a/models/user_openid.go +++ b/models/user_openid.go @@ -30,7 +30,7 @@ func init() { // GetUserOpenIDs returns all openid addresses that belongs to given user. func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) { openids := make([]*UserOpenID, 0, 5) - if err := db.DefaultContext().Engine(). + if err := db.GetEngine(db.DefaultContext). Where("uid=?", uid). Asc("id"). Find(&openids); err != nil { @@ -64,7 +64,7 @@ func addUserOpenID(e db.Engine, openid *UserOpenID) error { // AddUserOpenID adds an pre-verified/normalized OpenID URI to given user. func AddUserOpenID(openid *UserOpenID) error { - return addUserOpenID(db.DefaultContext().Engine(), openid) + return addUserOpenID(db.GetEngine(db.DefaultContext), openid) } // DeleteUserOpenID deletes an openid address of given user. @@ -75,9 +75,9 @@ func DeleteUserOpenID(openid *UserOpenID) (err error) { UID: openid.UID, } if openid.ID > 0 { - deleted, err = db.DefaultContext().Engine().ID(openid.ID).Delete(&address) + deleted, err = db.GetEngine(db.DefaultContext).ID(openid.ID).Delete(&address) } else { - deleted, err = db.DefaultContext().Engine(). + deleted, err = db.GetEngine(db.DefaultContext). Where("openid=?", openid.URI). Delete(&address) } @@ -92,7 +92,7 @@ func DeleteUserOpenID(openid *UserOpenID) (err error) { // ToggleUserOpenIDVisibility toggles visibility of an openid address of given user. func ToggleUserOpenIDVisibility(id int64) (err error) { - _, err = db.DefaultContext().Engine().Exec("update `user_open_id` set `show` = not `show` where `id` = ?", id) + _, err = db.GetEngine(db.DefaultContext).Exec("update `user_open_id` set `show` = not `show` where `id` = ?", id) return err } @@ -111,7 +111,7 @@ func GetUserByOpenID(uri string) (*User, error) { // Otherwise, check in openid table oid := &UserOpenID{} - has, err := db.DefaultContext().Engine().Where("uri=?", uri).Get(oid) + has, err := db.GetEngine(db.DefaultContext).Where("uri=?", uri).Get(oid) if err != nil { return nil, err } |