Cache users on list releases (#527)

tokarchuk/v1.17
Lunny Xiao 8 years ago committed by GitHub
parent 6f4ba6884c
commit 2d1a1fce93
  1. 36
      routers/repo/release.go

@ -73,6 +73,8 @@ func Releases(ctx *context.Context) {
// Temproray cache commits count of used branches to speed up. // Temproray cache commits count of used branches to speed up.
countCache := make(map[string]int64) countCache := make(map[string]int64)
var cacheUsers = make(map[int64]*models.User)
var ok bool
tags := make([]*models.Release, len(rawTags)) tags := make([]*models.Release, len(rawTags))
for i, rawTag := range rawTags { for i, rawTag := range rawTags {
for j, r := range releases { for j, r := range releases {
@ -80,14 +82,17 @@ func Releases(ctx *context.Context) {
continue continue
} }
if r.TagName == rawTag { if r.TagName == rawTag {
r.Publisher, err = models.GetUserByID(r.PublisherID) if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
if err != nil { r.Publisher, err = models.GetUserByID(r.PublisherID)
if models.IsErrUserNotExist(err) { if err != nil {
r.Publisher = models.NewGhostUser() if models.IsErrUserNotExist(err) {
} else { r.Publisher = models.NewGhostUser()
ctx.Handle(500, "GetUserByID", err) } else {
return ctx.Handle(500, "GetUserByID", err)
return
}
} }
cacheUsers[r.PublisherID] = r.Publisher
} }
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil {
@ -129,14 +134,17 @@ func Releases(ctx *context.Context) {
continue continue
} }
r.Publisher, err = models.GetUserByID(r.PublisherID) if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
if err != nil { r.Publisher, err = models.GetUserByID(r.PublisherID)
if models.IsErrUserNotExist(err) { if err != nil {
r.Publisher = models.NewGhostUser() if models.IsErrUserNotExist(err) {
} else { r.Publisher = models.NewGhostUser()
ctx.Handle(500, "GetUserByID", err) } else {
return ctx.Handle(500, "GetUserByID", err)
return
}
} }
cacheUsers[r.PublisherID] = r.Publisher
} }
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil { if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil {

Loading…
Cancel
Save