internal/store/stats.go

4a511e42574ead9c92dc73fd320f296cc4dbea07
gitbay/internal/store/stats.go

37 lines · 1095 bytes

3 symbols in this file
 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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form