From 5fe5301b69de36dc64cf350d6924cb3e7b54b9ba Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 16 Feb 2023 18:36:17 +0100 Subject: dashboard: cache per-subsystem stats For each subsystem, collect the number of open, fixed and invalid bugs. --- dashboard/app/cache.go | 46 +++++++++++++++++++++++++++++--------------- dashboard/app/handler.go | 4 ++-- 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 - 🐞 Open [{{$.Cached.Open}}] + 🐞 Open [{{$.BugCounts.Open}}] - 🐞 Fixed [{{$.Cached.Fixed}}] + 🐞 Fixed [{{$.BugCounts.Fixed}}] - 🐞 Invalid [{{$.Cached.Invalid}}] + 🐞 Invalid [{{$.BugCounts.Invalid}}] 📈 Kernel Health -- cgit mrf-deployment