diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-29 21:21:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-29 21:21:19 +0800 |
commit | 2d1a1fce934cb87cc67b85083d342b14bb52b780 (patch) | |
tree | d0e07add8dc1cfea679ee4c937d084849001c60e | |
parent | 6f4ba6884c85e5603e7510c0e0d114bc9f86965f (diff) | |
download | gitea-2d1a1fce934cb87cc67b85083d342b14bb52b780.tar.gz gitea-2d1a1fce934cb87cc67b85083d342b14bb52b780.zip |
Cache users on list releases (#527)
-rw-r--r-- | routers/repo/release.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/routers/repo/release.go b/routers/repo/release.go index dc5a54c6fb..9e4764db0e 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -73,6 +73,8 @@ func Releases(ctx *context.Context) { // Temproray cache commits count of used branches to speed up. countCache := make(map[string]int64) + var cacheUsers = make(map[int64]*models.User) + var ok bool tags := make([]*models.Release, len(rawTags)) for i, rawTag := range rawTags { for j, r := range releases { @@ -80,14 +82,17 @@ func Releases(ctx *context.Context) { continue } if r.TagName == rawTag { - r.Publisher, err = models.GetUserByID(r.PublisherID) - if err != nil { - if models.IsErrUserNotExist(err) { - r.Publisher = models.NewGhostUser() - } else { - ctx.Handle(500, "GetUserByID", err) - return + if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { + r.Publisher, err = models.GetUserByID(r.PublisherID) + if err != nil { + if models.IsErrUserNotExist(err) { + r.Publisher = models.NewGhostUser() + } else { + ctx.Handle(500, "GetUserByID", err) + return + } } + cacheUsers[r.PublisherID] = r.Publisher } if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { @@ -129,14 +134,17 @@ func Releases(ctx *context.Context) { continue } - r.Publisher, err = models.GetUserByID(r.PublisherID) - if err != nil { - if models.IsErrUserNotExist(err) { - r.Publisher = models.NewGhostUser() - } else { - ctx.Handle(500, "GetUserByID", err) - return + if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { + r.Publisher, err = models.GetUserByID(r.PublisherID) + if err != nil { + if models.IsErrUserNotExist(err) { + r.Publisher = models.NewGhostUser() + } else { + ctx.Handle(500, "GetUserByID", err) + return + } } + cacheUsers[r.PublisherID] = r.Publisher } if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { |