aboutsummaryrefslogtreecommitdiffstats
path: root/models/statistic.go
diff options
context:
space:
mode:
authorRomain <romdum@users.noreply.github.com>2021-10-05 20:39:37 +0200
committerGitHub <noreply@github.com>2021-10-05 20:39:37 +0200
commit987152ba408b03fe0b15dd9c72dfd1614b4159fd (patch)
tree02572cb5512f146797c3a3d715f0bee22eb138f7 /models/statistic.go
parent760d61b411460db3f3c688c214a6199b5b18eb27 (diff)
downloadgitea-987152ba408b03fe0b15dd9c72dfd1614b4159fd.tar.gz
gitea-987152ba408b03fe0b15dd9c72dfd1614b4159fd.zip
Add metrics to get issues by repository (#17225)
Diffstat (limited to 'models/statistic.go')
-rw-r--r--models/statistic.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/models/statistic.go b/models/statistic.go
index c80cebba99..5e72dc713d 100644
--- a/models/statistic.go
+++ b/models/statistic.go
@@ -21,7 +21,8 @@ type Statistic struct {
Milestone, Label, HookTask,
Team, UpdateTask, Project,
ProjectBoard, Attachment int64
- IssueByLabel []IssueByLabelCount
+ IssueByLabel []IssueByLabelCount
+ IssueByRepository []IssueByRepositoryCount
}
}
@@ -31,6 +32,13 @@ type IssueByLabelCount struct {
Label string
}
+// IssueByRepositoryCount contains the number of issue group by repository
+type IssueByRepositoryCount struct {
+ Count int64
+ OwnerName string
+ Repository string
+}
+
// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
e := db.GetEngine(db.DefaultContext)
@@ -58,6 +66,16 @@ func GetStatistic() (stats Statistic) {
Find(&stats.Counter.IssueByLabel)
}
+ if setting.Metrics.EnabledIssueByRepository {
+ stats.Counter.IssueByRepository = []IssueByRepositoryCount{}
+
+ _ = e.Select("COUNT(*) AS count, r.owner_name, r.name AS repository").
+ Join("LEFT", "repository r", "r.id=i.repo_id").
+ Table("issue i").
+ GroupBy("r.owner_name, r.name").
+ Find(&stats.Counter.IssueByRepository)
+ }
+
issueCounts := []IssueCount{}
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)