@@ -20,6 +20,7 @@ import (
20
20
"code.gitea.io/gitea/modules/gitrepo"
21
21
"code.gitea.io/gitea/modules/globallock"
22
22
"code.gitea.io/gitea/modules/log"
23
+ "code.gitea.io/gitea/modules/setting"
23
24
api "code.gitea.io/gitea/modules/structs"
24
25
)
25
26
@@ -98,10 +99,14 @@ func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *rep
98
99
return res , nil
99
100
}
100
101
102
+ ctx , cancel := context .WithTimeout (ctx , time .Duration (setting .Git .Timeout .Default )* time .Second )
103
+ defer cancel ()
104
+
101
105
res , err := generateContributorStats (ctx , repo , revision )
102
106
if err != nil {
103
107
return nil , err
104
108
}
109
+ cancel ()
105
110
106
111
_ = cache .PutJSON (cacheKey , res , contributorStatsCacheTimeout )
107
112
return res , nil
@@ -230,12 +235,17 @@ func generateContributorStats(ctx context.Context, repo *repo_model.Repository,
230
235
}
231
236
total := contributorsCommitStats ["total" ]
232
237
238
+ emailUserCache := make (map [string ]* user_model.User )
233
239
for _ , v := range extendedCommitStats {
234
240
userEmail := v .Author .Email
235
241
if len (userEmail ) == 0 {
236
242
continue
237
243
}
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
+ }
239
249
if u != nil {
240
250
// update userEmail with user's primary email address so
241
251
// that different mail addresses will linked to same account
0 commit comments