diff options
author | Romain <romdum@users.noreply.github.com> | 2021-08-07 11:43:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-07 12:43:50 +0300 |
commit | 14762abf0bebc57d355cf763c248cca4cbb60043 (patch) | |
tree | 8b8c53fc6ff5615fc7e4b476c121bed5b4068496 /models | |
parent | 620c5690ea509f54af24d983060f0897c9ada09b (diff) | |
download | gitea-14762abf0bebc57d355cf763c248cca4cbb60043.tar.gz gitea-14762abf0bebc57d355cf763c248cca4cbb60043.zip |
Separate open and closed issue in metrics (#16637)
* Get the issue counts in one query
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models')
-rwxr-xr-x[-rw-r--r--] | models/models.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/models/models.go b/models/models.go index 610933d327..378747dbce 100644..100755 --- a/models/models.go +++ b/models/models.go @@ -272,7 +272,8 @@ type Statistic struct { Counter struct { User, Org, PublicKey, Repo, Watch, Star, Action, Access, - Issue, Comment, Oauth, Follow, + Issue, IssueClosed, IssueOpen, + Comment, Oauth, Follow, Mirror, Release, LoginSource, Webhook, Milestone, Label, HookTask, Team, UpdateTask, Attachment int64 @@ -289,7 +290,24 @@ func GetStatistic() (stats Statistic) { stats.Counter.Star, _ = x.Count(new(Star)) stats.Counter.Action, _ = x.Count(new(Action)) stats.Counter.Access, _ = x.Count(new(Access)) - stats.Counter.Issue, _ = x.Count(new(Issue)) + + type IssueCount struct { + Count int64 + IsClosed bool + } + issueCounts := []IssueCount{} + + _ = x.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts) + for _, c := range issueCounts { + if c.IsClosed { + stats.Counter.IssueClosed = c.Count + } else { + stats.Counter.IssueOpen = c.Count + } + } + + stats.Counter.Issue = stats.Counter.IssueClosed + stats.Counter.IssueOpen + stats.Counter.Comment, _ = x.Count(new(Comment)) stats.Counter.Oauth = 0 stats.Counter.Follow, _ = x.Count(new(Follow)) |