@@ -48,7 +48,11 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
4848 return ParseCommitWithSignatureCommitter (ctx , c , committer )
4949}
5050
51- const cacheUserEmailAddressKey = "gpg_user_email_address"
51+ const (
52+ cacheUserEmailAddressKey = "gpg_user_email_address"
53+ cacheUserKey = "gpg_user"
54+ cacheGPGListKey = "gpg_key_list"
55+ )
5256
5357func ParseCommitWithSignatureCommitter (ctx context.Context , c * git.Commit , committer * user_model.User ) * asymkey_model.CommitVerification {
5458 // If no signature just report the committer
@@ -214,10 +218,13 @@ func checkKeyEmails(ctx context.Context, email string, keys ...*asymkey_model.GP
214218 }
215219 if key .Verified && key .OwnerID != 0 {
216220 if uid != key .OwnerID {
217- userEmails , _ = user_model .GetEmailAddresses (ctx , key .OwnerID )
221+ userEmails , _ = cache .GetWithContextCache (ctx , cacheUserEmailAddressKey , key .OwnerID , func () ([]* user_model.EmailAddress , error ) {
222+ return user_model .GetEmailAddresses (ctx , key .OwnerID )
223+ })
218224 uid = key .OwnerID
219- user = & user_model.User {ID : uid }
220- _ , _ = user_model .GetUser (ctx , user )
225+ user , _ = cache .GetWithContextCache (ctx , cacheUserKey , uid , func () (* user_model.User , error ) {
226+ return user_model .GetUserByID (ctx , uid )
227+ })
221228 }
222229 for _ , e := range userEmails {
223230 if e .IsActivated && (email == "" || strings .EqualFold (e .Email , email )) {
@@ -232,13 +239,11 @@ func checkKeyEmails(ctx context.Context, email string, keys ...*asymkey_model.GP
232239 return false , email
233240}
234241
235- const cacheGroupKey = "gpg_key_id"
236-
237242func HashAndVerifyForKeyID (ctx context.Context , sig * packet.Signature , payload string , committer * user_model.User , keyID , name , email string ) * asymkey_model.CommitVerification {
238243 if keyID == "" {
239244 return nil
240245 }
241- keys , err := cache .GetWithContextCache (ctx , cacheGroupKey , keyID , func () ([]* asymkey_model.GPGKey , error ) {
246+ keys , err := cache .GetWithContextCache (ctx , cacheGPGListKey , keyID , func () ([]* asymkey_model.GPGKey , error ) {
242247 return db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
243248 KeyID : keyID ,
244249 IncludeSubKeys : true ,
@@ -258,7 +263,7 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
258263 for _ , key := range keys {
259264 var primaryKeys []* asymkey_model.GPGKey
260265 if key .PrimaryKeyID != "" {
261- primaryKeys , err = cache .GetWithContextCache (ctx , cacheGroupKey , key .PrimaryKeyID , func () ([]* asymkey_model.GPGKey , error ) {
266+ primaryKeys , err = cache .GetWithContextCache (ctx , cacheGPGListKey , key .PrimaryKeyID , func () ([]* asymkey_model.GPGKey , error ) {
262267 return db .Find [asymkey_model.GPGKey ](ctx , asymkey_model.FindGPGKeyOptions {
263268 KeyID : key .PrimaryKeyID ,
264269 IncludeSubKeys : true ,
@@ -283,8 +288,10 @@ func HashAndVerifyForKeyID(ctx context.Context, sig *packet.Signature, payload s
283288 Name : name ,
284289 Email : email ,
285290 }
286- if key .OwnerID != 0 {
287- owner , err := user_model .GetUserByID (ctx , key .OwnerID )
291+ if key .OwnerID > 0 {
292+ owner , err := cache .GetWithContextCache (ctx , cacheUserKey , committer .ID , func () (* user_model.User , error ) {
293+ return user_model .GetUserByID (ctx , key .OwnerID )
294+ })
288295 if err == nil {
289296 signer = owner
290297 } else if ! user_model .IsErrUserNotExist (err ) {
@@ -392,7 +399,9 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
392399 }
393400 }
394401
395- committerEmailAddresses , err := user_model .GetEmailAddresses (ctx , committer .ID )
402+ committerEmailAddresses , err := cache .GetWithContextCache (ctx , cacheUserEmailAddressKey , committer .ID , func () ([]* user_model.EmailAddress , error ) {
403+ return user_model .GetEmailAddresses (ctx , committer .ID )
404+ })
396405 if err != nil {
397406 log .Error ("GetEmailAddresses: %v" , err )
398407 }
0 commit comments