Skip to content

Commit dcbb051

Browse files
silverwindclaude
andcommitted
perf(repo): cache no-match result in PushCommit.AuthorUser
GetWithContextCache only stores on success, so unmatched author emails re-queried the DB on every PushCommit render across a feed. Drop the helper and use the ephemeral cache directly so the nil result is cached for the rest of the request. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
1 parent f2363e6 commit dcbb051

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

modules/repository/commits.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,23 @@ func (pc *PushCommit) AuthorSignature() *git.Signature {
170170

171171
// AuthorUser resolves the author email to a Gitea user via per-request cache, nil if no match.
172172
func (pc *PushCommit) AuthorUser(ctx context.Context) *user_model.User {
173-
u, err := cache.GetWithContextCache(ctx, cachegroup.User, "email:"+pc.AuthorEmail, func(ctx context.Context, _ string) (*user_model.User, error) {
174-
return user_model.GetUserByEmail(ctx, pc.AuthorEmail)
175-
})
173+
c := cache.GetContextCache(ctx)
174+
key := "email:" + pc.AuthorEmail
175+
if c != nil {
176+
if v, has := c.Get(cachegroup.User, key); has {
177+
u, _ := v.(*user_model.User)
178+
return u
179+
}
180+
}
181+
u, err := user_model.GetUserByEmail(ctx, pc.AuthorEmail)
176182
if err != nil {
177183
if !user_model.IsErrUserNotExist(err) {
178184
log.Error("GetUserByEmail: %v", err)
179185
}
180-
return nil
186+
u = nil
187+
}
188+
if c != nil {
189+
c.Put(cachegroup.User, key, u)
181190
}
182191
return u
183192
}

0 commit comments

Comments
 (0)