Skip to content

Commit 1dbcf89

Browse files
committed
fix
1 parent 9d28a28 commit 1dbcf89

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

services/repository/contributors_graph.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"code.gitea.io/gitea/modules/gitrepo"
2121
"code.gitea.io/gitea/modules/globallock"
2222
"code.gitea.io/gitea/modules/log"
23+
"code.gitea.io/gitea/modules/setting"
2324
api "code.gitea.io/gitea/modules/structs"
2425
)
2526

@@ -98,10 +99,14 @@ func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *rep
9899
return res, nil
99100
}
100101

102+
ctx, cancel := context.WithTimeout(ctx, time.Duration(setting.Git.Timeout.Default)*time.Second)
103+
defer cancel()
104+
101105
res, err := generateContributorStats(ctx, repo, revision)
102106
if err != nil {
103107
return nil, err
104108
}
109+
cancel()
105110

106111
_ = cache.PutJSON(cacheKey, res, contributorStatsCacheTimeout)
107112
return res, nil
@@ -230,12 +235,17 @@ func generateContributorStats(ctx context.Context, repo *repo_model.Repository,
230235
}
231236
total := contributorsCommitStats["total"]
232237

238+
emailUserCache := make(map[string]*user_model.User)
233239
for _, v := range extendedCommitStats {
234240
userEmail := v.Author.Email
235241
if len(userEmail) == 0 {
236242
continue
237243
}
238-
u, _ := user_model.GetUserByEmail(ctx, userEmail)
244+
u, ok := emailUserCache[userEmail]
245+
if !ok {
246+
u, _ = user_model.GetUserByEmail(ctx, userEmail)
247+
emailUserCache[userEmail] = u
248+
}
239249
if u != nil {
240250
// update userEmail with user's primary email address so
241251
// that different mail addresses will linked to same account

0 commit comments

Comments
 (0)