diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-02-16 18:36:17 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-02-17 12:00:36 +0100 |
| commit | 5fe5301b69de36dc64cf350d6924cb3e7b54b9ba (patch) | |
| tree | 95c459356142f496a0402f2693d5683069ee5506 | |
| parent | 3e7039f40cdc73052372e83bef288c26ed5256d8 (diff) | |
dashboard: cache per-subsystem stats
For each subsystem, collect the number of open, fixed and invalid bugs.
| -rw-r--r-- | dashboard/app/cache.go | 46 | ||||
| -rw-r--r-- | dashboard/app/handler.go | 4 | ||||
| -rw-r--r-- | dashboard/app/templates.html | 6 |
3 files changed, 36 insertions, 20 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) } diff --git a/dashboard/app/handler.go b/dashboard/app/handler.go index 7c6e9a23e..cb998a516 100644 --- a/dashboard/app/handler.go +++ b/dashboard/app/handler.go @@ -127,7 +127,7 @@ type uiHeader struct { AnalyticsTrackingID string Subpage string Namespace string - Cached *Cached + BugCounts *CachedBugStats Namespaces []uiNamespace } @@ -209,7 +209,7 @@ func commonHeader(c context.Context, r *http.Request, w http.ResponseWriter, ns if err != nil { return nil, err } - h.Cached = cached + h.BugCounts = &cached.Total } return h, nil } diff --git a/dashboard/app/templates.html b/dashboard/app/templates.html index 0420aef25..2b7ef61c1 100644 --- a/dashboard/app/templates.html +++ b/dashboard/app/templates.html @@ -58,11 +58,11 @@ Use of this source code is governed by Apache 2 LICENSE that can be found in the <tr> <td class="navigation"> <a class="navigation_tab{{if eq .URLPath (printf "/%v" $.Namespace)}}_selected{{end}}" href='/{{$.Namespace}}'> - <span style="color:DeepPink;">π</span> Open [{{$.Cached.Open}}]</a> + <span style="color:DeepPink;">π</span> Open [{{$.BugCounts.Open}}]</a> <a class="navigation_tab{{if eq .URLPath (printf "/%v/fixed" $.Namespace)}}_selected{{end}}" href='/{{$.Namespace}}/fixed'> - <span style="color:ForestGreen;">π</span> Fixed [{{$.Cached.Fixed}}]</a> + <span style="color:ForestGreen;">π</span> Fixed [{{$.BugCounts.Fixed}}]</a> <a class="navigation_tab{{if eq .URLPath (printf "/%v/invalid" $.Namespace)}}_selected{{end}}" href='/{{$.Namespace}}/invalid'> - <span style="color:RoyalBlue;">π</span> Invalid [{{$.Cached.Invalid}}]</a> + <span style="color:RoyalBlue;">π</span> Invalid [{{$.BugCounts.Invalid}}]</a> <a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/bugs" $.Namespace)}}_selected{{end}}" href='/{{$.Namespace}}/graph/bugs'> <span style="color:DarkOrange;">π</span> Kernel Health</a> <a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/lifetimes" $.Namespace)}}_selected{{end}}" href='/{{$.Namespace}}/graph/lifetimes'> |
