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 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'dashboard/app/cache.go') 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) } -- cgit mrf-deployment