internal/store/stats.go
37 lines · 1095 bytes
1package store
2
3// ListAllRepos returns every repository, for host-local admin tooling.
4func (s *Store) ListAllRepos() ([]Repo, error) {
5 return queryAll(s.DB, scanRepo, repoSelect+" ORDER BY 4, r.name")
6}
7
8type Counts struct {
9 Users int64 `json:"users"`
10 Orgs int64 `json:"orgs"`
11 Repos int64 `json:"repos"`
12 Issues int64 `json:"issues"`
13 OpenIssues int64 `json:"open_issues"`
14 MRs int64 `json:"mrs"`
15 OpenMRs int64 `json:"open_mrs"`
16}
17
18func (s *Store) InstanceCounts() (Counts, error) {
19 var c Counts
20 for _, q := range []struct {
21 dst *int64
22 query string
23 }{
24 {&c.Users, "SELECT COUNT(*) FROM users"},
25 {&c.Orgs, "SELECT COUNT(*) FROM orgs"},
26 {&c.Repos, "SELECT COUNT(*) FROM repos"},
27 {&c.Issues, "SELECT COUNT(*) FROM issues"},
28 {&c.OpenIssues, "SELECT COUNT(*) FROM issues WHERE state = 'open'"},
29 {&c.MRs, "SELECT COUNT(*) FROM merge_requests"},
30 {&c.OpenMRs, "SELECT COUNT(*) FROM merge_requests WHERE state IN ('open','source_gone')"},
31 } {
32 if err := s.DB.QueryRow(q.query).Scan(q.dst); err != nil {
33 return c, err
34 }
35 }
36 return c, nil
37}