aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/cache.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-02-16 18:36:17 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-17 12:00:36 +0100
commit5fe5301b69de36dc64cf350d6924cb3e7b54b9ba (patch)
tree95c459356142f496a0402f2693d5683069ee5506 /dashboard/app/cache.go
parent3e7039f40cdc73052372e83bef288c26ed5256d8 (diff)
dashboard: cache per-subsystem stats
For each subsystem, collect the number of open, fixed and invalid bugs.
Diffstat (limited to 'dashboard/app/cache.go')
-rw-r--r--dashboard/app/cache.go46
1 files changed, 31 insertions, 15 deletions
diff --git a/dashboard/app/cache.go b/dashboard/app/cache.go
index 2b4178abc..177d4750f 100644
--- a/dashboard/app/cache.go
+++ b/dashboard/app/cache.go
@@ -15,6 +15,11 @@ import (
)
type Cached struct {
+ Total CachedBugStats
+ Subsystems map[string]CachedBugStats
+}
+
+type CachedBugStats struct {
Open int
Fixed int
Invalid int
@@ -58,22 +63,18 @@ func cacheUpdate(w http.ResponseWriter, r *http.Request) {
}
func buildAndStoreCached(c context.Context, bugs []*Bug, ns string, accessLevel AccessLevel) (*Cached, error) {
- v := &Cached{}
+ v := &Cached{
+ Subsystems: make(map[string]CachedBugStats),
+ }
for _, bug := range bugs {
- switch bug.Status {
- case BugStatusOpen:
- if accessLevel < bug.sanitizeAccess(accessLevel) {
- continue
- }
- if len(bug.Commits) == 0 {
- v.Open++
- } else {
- v.Fixed++
- }
- case BugStatusFixed:
- v.Fixed++
- case BugStatusInvalid:
- v.Invalid++
+ if bug.Status == BugStatusOpen && accessLevel < bug.sanitizeAccess(accessLevel) {
+ continue
+ }
+ v.Total.Record(bug)
+ for _, subsystem := range bug.Tags.Subsystems {
+ stats := v.Subsystems[subsystem.Name]
+ stats.Record(bug)
+ v.Subsystems[subsystem.Name] = stats
}
}
item := &memcache.Item{
@@ -87,6 +88,21 @@ func buildAndStoreCached(c context.Context, bugs []*Bug, ns string, accessLevel
return v, nil
}
+func (c *CachedBugStats) Record(bug *Bug) {
+ switch bug.Status {
+ case BugStatusOpen:
+ if len(bug.Commits) == 0 {
+ c.Open++
+ } else {
+ c.Fixed++
+ }
+ case BugStatusFixed:
+ c.Fixed++
+ case BugStatusInvalid:
+ c.Invalid++
+ }
+}
+
func cacheKey(ns string, accessLevel AccessLevel) string {
return fmt.Sprintf("%v-%v", ns, accessLevel)
}