summaryrefslogtreecommitdiffstats
path: root/routers/user/home.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-08-02 22:09:16 -0700
committerLunny Xiao <xiaolunwen@gmail.com>2017-08-03 13:09:16 +0800
commit7e0654bd9e4f90fc156884afd88cb82ad8df86a8 (patch)
tree03d320ee4a46d003ef5db801c1740b8d7ed9b966 /routers/user/home.go
parentf29458bd3a20d2d89638d5031d801c161f456374 (diff)
downloadgitea-7e0654bd9e4f90fc156884afd88cb82ad8df86a8.tar.gz
gitea-7e0654bd9e4f90fc156884afd88cb82ad8df86a8.zip
Fix counts on issues dashboard (#2215)
* Fix counts on issues dashboard * setupSess -> setupSession * Unit test * Load repo owners for issues
Diffstat (limited to 'routers/user/home.go')
-rw-r--r--routers/user/home.go98
1 files changed, 41 insertions, 57 deletions
diff --git a/routers/user/home.go b/routers/user/home.go
index 7128890690..b2096bc2ce 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -270,94 +270,77 @@ func Issues(ctx *context.Context) {
userRepoIDs = []int64{-1}
}
- var issues []*models.Issue
+ opts := &models.IssuesOptions{
+ RepoID: repoID,
+ IsClosed: util.OptionalBoolOf(isShowClosed),
+ IsPull: util.OptionalBoolOf(isPullList),
+ SortType: sortType,
+ }
+
switch filterMode {
case models.FilterModeAll:
- // Get all issues from repositories from this user.
- issues, err = models.Issues(&models.IssuesOptions{
- RepoIDs: userRepoIDs,
- RepoID: repoID,
- Page: page,
- IsClosed: util.OptionalBoolOf(isShowClosed),
- IsPull: util.OptionalBoolOf(isPullList),
- SortType: sortType,
- })
-
+ opts.RepoIDs = userRepoIDs
case models.FilterModeAssign:
- // Get all issues assigned to this user.
- issues, err = models.Issues(&models.IssuesOptions{
- RepoID: repoID,
- AssigneeID: ctxUser.ID,
- Page: page,
- IsClosed: util.OptionalBoolOf(isShowClosed),
- IsPull: util.OptionalBoolOf(isPullList),
- SortType: sortType,
- })
-
+ opts.AssigneeID = ctxUser.ID
case models.FilterModeCreate:
- // Get all issues created by this user.
- issues, err = models.Issues(&models.IssuesOptions{
- RepoID: repoID,
- PosterID: ctxUser.ID,
- Page: page,
- IsClosed: util.OptionalBoolOf(isShowClosed),
- IsPull: util.OptionalBoolOf(isPullList),
- SortType: sortType,
- })
+ opts.PosterID = ctxUser.ID
case models.FilterModeMention:
- // Get all issues created by this user.
- issues, err = models.Issues(&models.IssuesOptions{
- RepoID: repoID,
- MentionedID: ctxUser.ID,
- Page: page,
- IsClosed: util.OptionalBoolOf(isShowClosed),
- IsPull: util.OptionalBoolOf(isPullList),
- SortType: sortType,
- })
+ opts.MentionedID = ctxUser.ID
}
+ counts, err := models.CountIssuesByRepo(opts)
if err != nil {
- ctx.Handle(500, "Issues", err)
+ ctx.Handle(500, "CountIssuesByRepo", err)
return
}
- showRepos, err := models.IssueList(issues).LoadRepositories()
+ opts.Page = page
+ opts.PageSize = setting.UI.IssuePagingNum
+ issues, err := models.Issues(opts)
if err != nil {
- ctx.Handle(500, "LoadRepositories", fmt.Errorf("%v", err))
+ ctx.Handle(500, "Issues", err)
return
}
- if repoID > 0 {
- var theRepo *models.Repository
- for _, repo := range showRepos {
- if repo.ID == repoID {
- theRepo = repo
- break
- }
+ showReposMap := make(map[int64]*models.Repository, len(counts))
+ for repoID := range counts {
+ repo, err := models.GetRepositoryByID(repoID)
+ if err != nil {
+ ctx.Handle(500, "GetRepositoryByID", err)
+ return
}
+ showReposMap[repoID] = repo
+ }
- if theRepo == nil {
- theRepo, err = models.GetRepositoryByID(repoID)
+ if repoID > 0 {
+ if _, ok := showReposMap[repoID]; !ok {
+ repo, err := models.GetRepositoryByID(repoID)
if err != nil {
- ctx.Handle(500, "GetRepositoryByID", fmt.Errorf("[#%d]%v", repoID, err))
+ ctx.Handle(500, "GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err))
return
}
- showRepos = append(showRepos, theRepo)
+ showReposMap[repoID] = repo
}
+ repo := showReposMap[repoID]
+
// Check if user has access to given repository.
- if !theRepo.IsOwnedBy(ctxUser.ID) && !theRepo.HasAccess(ctxUser) {
- ctx.Handle(404, "Issues", fmt.Errorf("#%d", repoID))
+ if !repo.IsOwnedBy(ctxUser.ID) && !repo.HasAccess(ctxUser) {
+ ctx.Status(404)
return
}
}
- err = models.RepositoryList(showRepos).LoadAttributes()
- if err != nil {
+ showRepos := models.RepositoryListOfMap(showReposMap)
+ if err = showRepos.LoadAttributes(); err != nil {
ctx.Handle(500, "LoadAttributes", fmt.Errorf("%v", err))
return
}
+ for _, issue := range issues {
+ issue.Repo = showReposMap[issue.RepoID]
+ }
+
issueStats := models.GetUserIssueStats(repoID, ctxUser.ID, userRepoIDs, filterMode, isPullList)
var total int
@@ -369,6 +352,7 @@ func Issues(ctx *context.Context) {
ctx.Data["Issues"] = issues
ctx.Data["Repos"] = showRepos
+ ctx.Data["Counts"] = counts
ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
ctx.Data["IssueStats"] = issueStats
ctx.Data["ViewType"] = viewType