1
0
Fork 0
forked from forgejo/forgejo

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:
Lunny Xiao 2022-05-20 22:08:52 +08:00 committed by GitHub
parent d81e31ad78
commit fd7d83ace6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
232 changed files with 1463 additions and 2108 deletions

View file

@ -31,10 +31,9 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public
return nil, err
}
defer committer.Close()
sess := db.GetEngine(ctx)
// Principals cannot be duplicated.
has, err := sess.
has, err := db.GetEngine(ctx).
Where("content = ? AND type = ?", content, KeyTypePrincipal).
Get(new(PublicKey))
if err != nil {
@ -51,7 +50,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public
Type: KeyTypePrincipal,
LoginSourceID: authSourceID,
}
if err = addPrincipalKey(sess, key); err != nil {
if err = db.Insert(ctx, key); err != nil {
return nil, fmt.Errorf("addKey: %v", err)
}
@ -61,16 +60,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public
committer.Close()
return key, RewriteAllPrincipalKeys()
}
func addPrincipalKey(e db.Engine, key *PublicKey) (err error) {
// Save Key representing a principal.
if _, err = e.Insert(key); err != nil {
return err
}
return nil
return key, RewriteAllPrincipalKeys(db.DefaultContext)
}
// CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines