2021-09-19 07:49:59 -04:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
2021-09-24 07:32:56 -04:00
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/login"
|
|
|
|
)
|
2021-09-19 07:49:59 -04:00
|
|
|
|
|
|
|
// Statistic contains the database statistics
|
|
|
|
type Statistic struct {
|
|
|
|
Counter struct {
|
|
|
|
User, Org, PublicKey,
|
|
|
|
Repo, Watch, Star, Action, Access,
|
|
|
|
Issue, IssueClosed, IssueOpen,
|
|
|
|
Comment, Oauth, Follow,
|
|
|
|
Mirror, Release, LoginSource, Webhook,
|
|
|
|
Milestone, Label, HookTask,
|
2021-10-01 21:32:15 -04:00
|
|
|
Team, UpdateTask, Project,
|
|
|
|
ProjectBoard, Attachment int64
|
2021-09-19 07:49:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStatistic returns the database statistics
|
|
|
|
func GetStatistic() (stats Statistic) {
|
2021-10-01 21:32:15 -04:00
|
|
|
e := db.GetEngine(db.DefaultContext)
|
2021-09-19 07:49:59 -04:00
|
|
|
stats.Counter.User = CountUsers()
|
|
|
|
stats.Counter.Org = CountOrganizations()
|
2021-10-01 21:32:15 -04:00
|
|
|
stats.Counter.PublicKey, _ = e.Count(new(PublicKey))
|
2021-09-19 07:49:59 -04:00
|
|
|
stats.Counter.Repo = CountRepositories(true)
|
2021-10-01 21:32:15 -04:00
|
|
|
stats.Counter.Watch, _ = e.Count(new(Watch))
|
|
|
|
stats.Counter.Star, _ = e.Count(new(Star))
|
|
|
|
stats.Counter.Action, _ = e.Count(new(Action))
|
|
|
|
stats.Counter.Access, _ = e.Count(new(Access))
|
2021-09-19 07:49:59 -04:00
|
|
|
|
|
|
|
type IssueCount struct {
|
|
|
|
Count int64
|
|
|
|
IsClosed bool
|
|
|
|
}
|
|
|
|
issueCounts := []IssueCount{}
|
|
|
|
|
2021-10-01 21:32:15 -04:00
|
|
|
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)
|
2021-09-19 07:49:59 -04:00
|
|
|
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
|
|
|
|
|
2021-10-01 21:32:15 -04:00
|
|
|
stats.Counter.Comment, _ = e.Count(new(Comment))
|
2021-09-19 07:49:59 -04:00
|
|
|
stats.Counter.Oauth = 0
|
2021-10-01 21:32:15 -04:00
|
|
|
stats.Counter.Follow, _ = e.Count(new(Follow))
|
|
|
|
stats.Counter.Mirror, _ = e.Count(new(Mirror))
|
|
|
|
stats.Counter.Release, _ = e.Count(new(Release))
|
2021-09-24 07:32:56 -04:00
|
|
|
stats.Counter.LoginSource = login.CountSources()
|
2021-10-01 21:32:15 -04:00
|
|
|
stats.Counter.Webhook, _ = e.Count(new(Webhook))
|
|
|
|
stats.Counter.Milestone, _ = e.Count(new(Milestone))
|
|
|
|
stats.Counter.Label, _ = e.Count(new(Label))
|
|
|
|
stats.Counter.HookTask, _ = e.Count(new(HookTask))
|
|
|
|
stats.Counter.Team, _ = e.Count(new(Team))
|
|
|
|
stats.Counter.Attachment, _ = e.Count(new(Attachment))
|
|
|
|
stats.Counter.Project, _ = e.Count(new(Project))
|
|
|
|
stats.Counter.ProjectBoard, _ = e.Count(new(ProjectBoard))
|
2021-09-19 07:49:59 -04:00
|
|
|
return
|
|
|
|
}
|