aboutsummaryrefslogtreecommitdiffstats
path: root/models/statistic.go
diff options
context:
space:
mode:
authorRomain <romdum@users.noreply.github.com>2021-10-04 00:46:44 +0200
committerGitHub <noreply@github.com>2021-10-03 18:46:44 -0400
commitfc5ee1edf90eb826a67921bb8d5c6b3e8c746225 (patch)
tree92f9987a5ecab529f23f17f07bf52a1cd9a35e08 /models/statistic.go
parent89ddbe9699aa2471af34d0e093e6631711482d89 (diff)
downloadgitea-fc5ee1edf90eb826a67921bb8d5c6b3e8c746225.tar.gz
gitea-fc5ee1edf90eb826a67921bb8d5c6b3e8c746225.zip
Add metrics to get issues by label (#17201)
* Add metrics to get issues by label * Add comment on IssueByLabelCount * Code review - Unify "AS" in SQL (#17201) * Code review - Remove useless join (#17201) * Code review - Disable issue_by_label by default in settings (#17201) * use e * restore empty line * update docs Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/statistic.go')
-rw-r--r--models/statistic.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/models/statistic.go b/models/statistic.go
index 1fdcc44a6f..c80cebba99 100644
--- a/models/statistic.go
+++ b/models/statistic.go
@@ -7,6 +7,7 @@ package models
import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
+ "code.gitea.io/gitea/modules/setting"
)
// Statistic contains the database statistics
@@ -20,9 +21,16 @@ type Statistic struct {
Milestone, Label, HookTask,
Team, UpdateTask, Project,
ProjectBoard, Attachment int64
+ IssueByLabel []IssueByLabelCount
}
}
+// IssueByLabelCount contains the number of issue group by label
+type IssueByLabelCount struct {
+ Count int64
+ Label string
+}
+
// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
e := db.GetEngine(db.DefaultContext)
@@ -39,6 +47,17 @@ func GetStatistic() (stats Statistic) {
Count int64
IsClosed bool
}
+
+ if setting.Metrics.EnabledIssueByLabel {
+ stats.Counter.IssueByLabel = []IssueByLabelCount{}
+
+ _ = e.Select("COUNT(*) AS count, l.name AS label").
+ Join("LEFT", "label l", "l.id=il.label_id").
+ Table("issue_label il").
+ GroupBy("l.name").
+ Find(&stats.Counter.IssueByLabel)
+ }
+
issueCounts := []IssueCount{}
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)