diff options
author | Bo-Yi Wu <appleboy.tw@gmail.com> | 2018-02-21 18:55:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-21 18:55:34 +0800 |
commit | 04b3e8cbdc2bb4eafe8feb3fe4882f010e931860 (patch) | |
tree | ca463be266c44aaf52e5106aac77dfd56402057b /routers/user/home.go | |
parent | d27d720f05835dfc4633587aec885ab9b93b5f86 (diff) | |
download | gitea-04b3e8cbdc2bb4eafe8feb3fe4882f010e931860.tar.gz gitea-04b3e8cbdc2bb4eafe8feb3fe4882f010e931860.zip |
refactor: reduce sql query in retrieveFeeds (#3547)
Diffstat (limited to 'routers/user/home.go')
-rw-r--r-- | routers/user/home.go | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index 5687cb4f1a..2a193bbdef 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -66,39 +66,14 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { if ctx.User != nil { userCache[ctx.User.ID] = ctx.User } - repoCache := map[int64]*models.Repository{} for _, act := range actions { - // Cache results to reduce queries. - u, ok := userCache[act.ActUserID] - if !ok { - u, err = models.GetUserByID(act.ActUserID) - if err != nil { - if models.IsErrUserNotExist(err) { - continue - } - ctx.ServerError("GetUserByID", err) - return - } - userCache[act.ActUserID] = u - } - act.ActUser = u - - repo, ok := repoCache[act.RepoID] - if !ok { - repo, err = models.GetRepositoryByID(act.RepoID) - if err != nil { - if models.IsErrRepoNotExist(err) { - continue - } - ctx.ServerError("GetRepositoryByID", err) - return - } + if act.ActUser != nil { + userCache[act.ActUserID] = act.ActUser } - act.Repo = repo - repoOwner, ok := userCache[repo.OwnerID] + repoOwner, ok := userCache[act.Repo.OwnerID] if !ok { - repoOwner, err = models.GetUserByID(repo.OwnerID) + repoOwner, err = models.GetUserByID(act.Repo.OwnerID) if err != nil { if models.IsErrUserNotExist(err) { continue @@ -106,8 +81,9 @@ func retrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) { ctx.ServerError("GetUserByID", err) return } + userCache[repoOwner.ID] = repoOwner } - repo.Owner = repoOwner + act.Repo.Owner = repoOwner } ctx.Data["Feeds"] = actions } @@ -154,7 +130,8 @@ func Dashboard(ctx *context.Context) { ctx.Data["MirrorCount"] = len(mirrors) ctx.Data["Mirrors"] = mirrors - retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser, + retrieveFeeds(ctx, models.GetFeedsOptions{ + RequestedUser: ctxUser, IncludePrivate: true, OnlyPerformedBy: false, IncludeDeleted: false, |