@@ -12,6 +12,7 @@ import (
1212 "code.gitea.io/gitea/models/db"
1313 user_model "code.gitea.io/gitea/models/user"
1414 "code.gitea.io/gitea/modules/cache"
15+ "code.gitea.io/gitea/modules/cachegroup"
1516 "code.gitea.io/gitea/modules/git"
1617 "code.gitea.io/gitea/modules/log"
1718 "code.gitea.io/gitea/modules/setting"
@@ -48,12 +49,6 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
4849 return ParseCommitWithSignatureCommitter (ctx , c , committer )
4950}
5051
51- const (
52- cacheUserEmailAddressKey = "gpg_user_email_address"
53- cacheUserKey = "gpg_user"
54- cacheGPGListKey = "gpg_key_list"
55- )
56-
5752func ParseCommitWithSignatureCommitter (ctx context.Context , c * git.Commit , committer * user_model.User ) * asymkey_model.CommitVerification {
5853 // If no signature just report the committer
5954 if c .Signature == nil {
@@ -122,9 +117,7 @@ func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, commi
122117 }
123118 }
124119
125- committerEmailAddresses , _ := cache .GetWithContextCache (ctx , cacheUserEmailAddressKey , committer .ID , func () ([]* user_model.EmailAddress , error ) {
126- return user_model .GetEmailAddresses (ctx , committer .ID )
127- })
120+ committerEmailAddresses , _ := cache .GetWithContextCache (ctx , cachegroup .UserEmailAddresses , committer .ID , user_model .GetEmailAddresses )
128121 activated := false
129122 for _ , e := range committerEmailAddresses {
130123 if e .IsActivated && strings .EqualFold (e .Email , c .Committer .Email ) {
@@ -218,13 +211,9 @@ func checkKeyEmails(ctx context.Context, email string, keys ...*asymkey_model.GP
218211 }
219212 if key .Verified && key .OwnerID != 0 {
220213 if uid != key .OwnerID {
221- userEmails , _ = cache .GetWithContextCache (ctx , cacheUserEmailAddressKey , key .OwnerID , func () ([]* user_model.EmailAddress , error ) {
222- return user_model .GetEmailAddresses (ctx , key .OwnerID )
223- })
214+ userEmails , _ = cache .GetWithContextCache (ctx , cachegroup .UserEmailAddresses , key .OwnerID , user_model .GetEmailAddresses )
224215 uid = key .OwnerID
225- user , _ = cache .GetWithContextCache (ctx , cacheUserKey , uid , func () (* user_model.User , error ) {
226- return user_model .GetUserByID (ctx , uid )
227- })
216+ user , _ = cache .GetWithContextCache (ctx , cachegroup .User , uid , user_model .GetUserByID )
228217 }
229218 for _ , e := range userEmails {
230219 if e .IsActivated && (email == "" || strings .EqualFold (e .Email , email )) {
@@ -243,12 +232,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
243232 if keyID == "" {
244233 return nil
245234 }
246- keys , err := cache .GetWithContextCache (ctx , cacheGPGListKey , keyID , func () ([]* asymkey_model.GPGKey , error ) {
247- return db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
248- KeyID : keyID ,
249- IncludeSubKeys : true ,
250- })
251- })
235+ keys , err := cache .GetWithContextCache (ctx , cachegroup .GPGKeyWithSubKeys , keyID , asymkey_model .FindGPGKeyWithSubKeys )
252236 if err != nil {
253237 log .Error ("GetGPGKeysByKeyID: %v" , err )
254238 return & asymkey_model.CommitVerification {
@@ -263,12 +247,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
263247 for _ , key := range keys {
264248 var primaryKeys []* asymkey_model.GPGKey
265249 if key .PrimaryKeyID != "" {
266- primaryKeys , err = cache .GetWithContextCache (ctx , cacheGPGListKey , key .PrimaryKeyID , func () ([]* asymkey_model.GPGKey , error ) {
267- return db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
268- KeyID : key .PrimaryKeyID ,
269- IncludeSubKeys : true ,
270- })
271- })
250+ primaryKeys , err = cache .GetWithContextCache (ctx , cachegroup .GPGKeyWithSubKeys , key .PrimaryKeyID , asymkey_model .FindGPGKeyWithSubKeys )
272251 if err != nil {
273252 log .Error ("GetGPGKeysByKeyID: %v" , err )
274253 return & asymkey_model.CommitVerification {
@@ -289,9 +268,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
289268 Email : email ,
290269 }
291270 if key .OwnerID > 0 {
292- owner , err := cache .GetWithContextCache (ctx , cacheUserKey , key .OwnerID , func () (* user_model.User , error ) {
293- return user_model .GetUserByID (ctx , key .OwnerID )
294- })
271+ owner , err := cache .GetWithContextCache (ctx , cachegroup .User , key .OwnerID , user_model .GetUserByID )
295272 if err == nil {
296273 signer = owner
297274 } else if ! user_model .IsErrUserNotExist (err ) {
@@ -399,9 +376,7 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
399376 }
400377 }
401378
402- committerEmailAddresses , err := cache .GetWithContextCache (ctx , cacheUserEmailAddressKey , committer .ID , func () ([]* user_model.EmailAddress , error ) {
403- return user_model .GetEmailAddresses (ctx , committer .ID )
404- })
379+ committerEmailAddresses , err := cache .GetWithContextCache (ctx , cachegroup .UserEmailAddresses , committer .ID , user_model .GetEmailAddresses )
405380 if err != nil {
406381 log .Error ("GetEmailAddresses: %v" , err )
407382 }
0 commit comments