Skip to content

Commit d7d0194

Browse files
committed
Cache commit verification
1 parent 3bbacac commit d7d0194

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

modules/templates/util_avatar.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ func (au *AvatarUtils) Avatar(item any, others ...any) template.HTML {
4343

4444
switch t := item.(type) {
4545
case *user_model.User:
46-
src := t.AvatarLinkWithSize(au.ctx, size*setting.Avatar.RenderedSizeFactor)
47-
if src != "" {
48-
return AvatarHTML(src, size, class, t.DisplayName())
46+
if t != nil && t.ID != 0 {
47+
src := t.AvatarLinkWithSize(au.ctx, size*setting.Avatar.RenderedSizeFactor)
48+
if src != "" {
49+
return AvatarHTML(src, size, class, t.DisplayName())
50+
}
4951
}
5052
case *repo_model.Collaborator:
5153
src := t.AvatarLinkWithSize(au.ctx, size*setting.Avatar.RenderedSizeFactor)

services/git/commit.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package git
55

66
import (
77
"context"
8+
"fmt"
89

910
asymkey_model "code.gitea.io/gitea/models/asymkey"
1011
"code.gitea.io/gitea/models/db"
@@ -18,9 +19,6 @@ import (
1819

1920
// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
2021
func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error)) ([]*asymkey_model.SignCommit, error) {
21-
newCommits := make([]*asymkey_model.SignCommit, 0, len(oldCommits))
22-
keyMap := map[string]bool{}
23-
2422
emails := make(container.Set[string])
2523
for _, c := range oldCommits {
2624
if c.Committer != nil {
@@ -33,6 +31,9 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use
3331
return nil, err
3432
}
3533

34+
newCommits := make([]*asymkey_model.SignCommit, 0, len(oldCommits))
35+
keyMap := map[string]bool{}
36+
cachedVerifications := make(map[string]*asymkey_model.CommitVerification)
3637
for _, c := range oldCommits {
3738
committer, ok := emailUsers[c.Committer.Email]
3839
if !ok && c.Committer != nil {
@@ -42,9 +43,19 @@ func ParseCommitsWithSignature(ctx context.Context, oldCommits []*user_model.Use
4243
}
4344
}
4445

46+
key := committer.Email
47+
if c.Signature != nil {
48+
key += fmt.Sprintf("-%s", c.Signature.Signature)
49+
}
50+
verification, ok := cachedVerifications[key]
51+
if !ok {
52+
verification = asymkey_service.ParseCommitWithSignatureCommitter(ctx, c.Commit, committer)
53+
cachedVerifications[key] = verification
54+
}
55+
4556
signCommit := &asymkey_model.SignCommit{
4657
UserCommit: c,
47-
Verification: asymkey_service.ParseCommitWithSignatureCommitter(ctx, c.Commit, committer),
58+
Verification: verification,
4859
}
4960

5061
_ = asymkey_model.CalculateTrustStatus(signCommit.Verification, repoTrustModel, isOwnerMemberCollaborator, &keyMap)

0 commit comments

Comments
 (0)