mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
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>
This commit is contained in:
parent
89ddbe9699
commit
fc5ee1edf9
5 changed files with 44 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue