diff options
author | Unknwon <u@gogs.io> | 2016-12-27 22:01:18 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-12-27 22:01:18 +0800 |
commit | 8059175a5c0363519ba28fb8fc5f9d494f6a209d (patch) | |
tree | f21775c9c1abbdad73b1d6d98984f5ac1780cba4 /models | |
parent | f8fd084bd2c7c2a4d642daad59dceaf40686269e (diff) |
Fix dashboard issues/pull request counting
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 12 | ||||
-rw-r--r-- | models/repo.go | 49 | ||||
-rw-r--r-- | models/user.go | 7 |
3 files changed, 57 insertions, 11 deletions
diff --git a/models/issue.go b/models/issue.go index 8c602d78..d17bc207 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1169,7 +1169,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats { // GetUserIssueStats returns issue statistic information for dashboard by given conditions. func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterMode, isPull bool) *IssueStats { stats := &IssueStats{} - + hasAnyRepo := repoID > 0 || repoIDs != nil countSession := func(isClosed, isPull bool, repoID int64, repoIDs []int64) *xorm.Session { sess := x.Where("issue.is_closed = ?", isClosed).And("issue.is_pull = ?", isPull) @@ -1190,11 +1190,17 @@ func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterM And("poster_id = ?", userID). Count(new(Issue)) - stats.YourReposCount, _ = countSession(false, isPull, repoID, repoIDs). - Count(new(Issue)) + if hasAnyRepo { + stats.YourReposCount, _ = countSession(false, isPull, repoID, repoIDs). + Count(new(Issue)) + } switch filterMode { case FILTER_MODE_YOUR_REPOS: + if !hasAnyRepo { + break + } + stats.OpenCount, _ = countSession(false, isPull, repoID, repoIDs). Count(new(Issue)) stats.ClosedCount, _ = countSession(true, isPull, repoID, repoIDs). diff --git a/models/repo.go b/models/repo.go index e6f12b2f..f9e52682 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1055,6 +1055,34 @@ func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) { return repos, nil } +// FilterRepositoryWithIssues selects repositories that are using interal issue tracker +// and has disabled external tracker from given set. +// It returns nil if result set is empty. +func FilterRepositoryWithIssues(repoIDs []int64) ([]int64, error) { + if len(repoIDs) == 0 { + return nil, nil + } + + repos := make([]*Repository, 0, len(repoIDs)) + if err := x.Where("enable_issues=?", true). + And("enable_external_tracker=?", false). + In("id", repoIDs). + Cols("id"). + Find(&repos); err != nil { + return nil, fmt.Errorf("filter valid repositories %v: %v", repoIDs, err) + } + + if len(repos) == 0 { + return nil, nil + } + + repoIDs = make([]int64, len(repos)) + for i := range repos { + repoIDs[i] = repos[i].ID + } + return repoIDs, nil +} + // RepoPath returns repository path by given user and repository name. func RepoPath(userName, repoName string) string { return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") @@ -1454,19 +1482,26 @@ func GetRepositoryByID(id int64) (*Repository, error) { return getRepositoryByID(x, id) } +type UserRepoOptions struct { + UserID int64 + Private bool + Page int + PageSize int +} + // GetUserRepositories returns a list of repositories of given user. -func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) { - sess := x.Where("owner_id = ?", userID).Desc("updated_unix") - if !private { +func GetUserRepositories(opts *UserRepoOptions) ([]*Repository, error) { + sess := x.Where("owner_id=?", opts.UserID).Desc("updated_unix") + if !opts.Private { sess.And("is_private=?", false) } - if page <= 0 { - page = 1 + if opts.Page <= 0 { + opts.Page = 1 } - sess.Limit(pageSize, (page-1)*pageSize) + sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) - repos := make([]*Repository, 0, pageSize) + repos := make([]*Repository, 0, opts.PageSize) return repos, sess.Find(&repos) } diff --git a/models/user.go b/models/user.go index 7946915d..4b842339 100644 --- a/models/user.go +++ b/models/user.go @@ -418,7 +418,12 @@ func (u *User) GetOrganizationCount() (int64, error) { // GetRepositories returns repositories that user owns, including private repositories. func (u *User) GetRepositories(page, pageSize int) (err error) { - u.Repos, err = GetUserRepositories(u.ID, true, page, pageSize) + u.Repos, err = GetUserRepositories(&UserRepoOptions{ + UserID: u.ID, + Private: true, + Page: page, + PageSize: pageSize, + }) return err } |