@@ -11,6 +11,8 @@ import (
11
11
asymkey_model "code.gitea.io/gitea/models/asymkey"
12
12
"code.gitea.io/gitea/models/db"
13
13
user_model "code.gitea.io/gitea/models/user"
14
+ "code.gitea.io/gitea/modules/cache"
15
+ "code.gitea.io/gitea/modules/cachegroup"
14
16
"code.gitea.io/gitea/modules/git"
15
17
"code.gitea.io/gitea/modules/log"
16
18
"code.gitea.io/gitea/modules/setting"
@@ -115,7 +117,7 @@ func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, commi
115
117
}
116
118
}
117
119
118
- committerEmailAddresses , _ := user_model . GetEmailAddresses (ctx , committer .ID )
120
+ committerEmailAddresses , _ := cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , committer .ID , user_model . GetEmailAddresses )
119
121
activated := false
120
122
for _ , e := range committerEmailAddresses {
121
123
if e .IsActivated && strings .EqualFold (e .Email , c .Committer .Email ) {
@@ -209,10 +211,9 @@ func checkKeyEmails(ctx context.Context, email string, keys ...*asymkey_model.GP
209
211
}
210
212
if key .Verified && key .OwnerID != 0 {
211
213
if uid != key .OwnerID {
212
- userEmails , _ = user_model . GetEmailAddresses (ctx , key .OwnerID )
214
+ userEmails , _ = cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , key .OwnerID , user_model . GetEmailAddresses )
213
215
uid = key .OwnerID
214
- user = & user_model.User {ID : uid }
215
- _ , _ = user_model .GetUser (ctx , user )
216
+ user , _ = cache .GetWithContextCache (ctx , cachegroup .User , uid , user_model .GetUserByID )
216
217
}
217
218
for _ , e := range userEmails {
218
219
if e .IsActivated && (email == "" || strings .EqualFold (e .Email , email )) {
@@ -231,10 +232,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
231
232
if keyID == "" {
232
233
return nil
233
234
}
234
- keys , err := db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
235
- KeyID : keyID ,
236
- IncludeSubKeys : true ,
237
- })
235
+ keys , err := cache .GetWithContextCache (ctx , cachegroup .GPGKeyWithSubKeys , keyID , asymkey_model .FindGPGKeyWithSubKeys )
238
236
if err != nil {
239
237
log .Error ("GetGPGKeysByKeyID: %v" , err )
240
238
return & asymkey_model.CommitVerification {
@@ -249,10 +247,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
249
247
for _ , key := range keys {
250
248
var primaryKeys []* asymkey_model.GPGKey
251
249
if key .PrimaryKeyID != "" {
252
- primaryKeys , err = db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
253
- KeyID : key .PrimaryKeyID ,
254
- IncludeSubKeys : true ,
255
- })
250
+ primaryKeys , err = cache .GetWithContextCache (ctx , cachegroup .GPGKeyWithSubKeys , key .PrimaryKeyID , asymkey_model .FindGPGKeyWithSubKeys )
256
251
if err != nil {
257
252
log .Error ("GetGPGKeysByKeyID: %v" , err )
258
253
return & asymkey_model.CommitVerification {
@@ -272,8 +267,8 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
272
267
Name : name ,
273
268
Email : email ,
274
269
}
275
- if key .OwnerID != 0 {
276
- owner , err := user_model . GetUserByID (ctx , key .OwnerID )
270
+ if key .OwnerID > 0 {
271
+ owner , err := cache . GetWithContextCache (ctx , cachegroup . User , key .OwnerID , user_model . GetUserByID )
277
272
if err == nil {
278
273
signer = owner
279
274
} else if ! user_model .IsErrUserNotExist (err ) {
@@ -381,7 +376,7 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
381
376
}
382
377
}
383
378
384
- committerEmailAddresses , err := user_model . GetEmailAddresses (ctx , committer .ID )
379
+ committerEmailAddresses , err := cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , committer .ID , user_model . GetEmailAddresses )
385
380
if err != nil {
386
381
log .Error ("GetEmailAddresses: %v" , err )
387
382
}
0 commit comments