@@ -11,6 +11,8 @@ import (
1111 asymkey_model "code.gitea.io/gitea/models/asymkey"
1212 "code.gitea.io/gitea/models/db"
1313 user_model "code.gitea.io/gitea/models/user"
14+ "code.gitea.io/gitea/modules/cache"
15+ "code.gitea.io/gitea/modules/cachegroup"
1416 "code.gitea.io/gitea/modules/git"
1517 "code.gitea.io/gitea/modules/log"
1618 "code.gitea.io/gitea/modules/setting"
@@ -115,7 +117,7 @@ func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, commi
115117 }
116118 }
117119
118- committerEmailAddresses , _ := user_model . GetEmailAddresses (ctx , committer .ID )
120+ committerEmailAddresses , _ := cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , committer .ID , user_model . GetEmailAddresses )
119121 activated := false
120122 for _ , e := range committerEmailAddresses {
121123 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
209211 }
210212 if key .Verified && key .OwnerID != 0 {
211213 if uid != key .OwnerID {
212- userEmails , _ = user_model . GetEmailAddresses (ctx , key .OwnerID )
214+ userEmails , _ = cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , key .OwnerID , user_model . GetEmailAddresses )
213215 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 )
216217 }
217218 for _ , e := range userEmails {
218219 if e .IsActivated && (email == "" || strings .EqualFold (e .Email , email )) {
@@ -231,10 +232,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
231232 if keyID == "" {
232233 return nil
233234 }
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 )
238236 if err != nil {
239237 log .Error ("GetGPGKeysByKeyID: %v" , err )
240238 return & asymkey_model.CommitVerification {
@@ -249,10 +247,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
249247 for _ , key := range keys {
250248 var primaryKeys []* asymkey_model.GPGKey
251249 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 )
256251 if err != nil {
257252 log .Error ("GetGPGKeysByKeyID: %v" , err )
258253 return & asymkey_model.CommitVerification {
@@ -272,8 +267,8 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
272267 Name : name ,
273268 Email : email ,
274269 }
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 )
277272 if err == nil {
278273 signer = owner
279274 } else if ! user_model .IsErrUserNotExist (err ) {
@@ -381,7 +376,7 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
381376 }
382377 }
383378
384- committerEmailAddresses , err := user_model . GetEmailAddresses (ctx , committer .ID )
379+ committerEmailAddresses , err := cache . GetWithContextCache (ctx , cachegroup . UserEmailAddresses , committer .ID , user_model . GetEmailAddresses )
385380 if err != nil {
386381 log .Error ("GetEmailAddresses: %v" , err )
387382 }
0 commit comments