Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache users on list releases #527

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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