Skip to content

Commit

Permalink
Cache users on list releases (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Dec 29, 2016
1 parent 6f4ba68 commit 2d1a1fc
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,26 @@ 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 {
if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) {
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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d1a1fc

Please sign in to comment.