From fd3bba535d0200374dad3bd872650a4ceb075cf2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 30 Jun 2020 20:01:01 +0200 Subject: dashboard/app: cache per-namespace bug stats We used to show number of fixed bugs at the top of the main page. However, now with the button nagivation, "fixed" is shown on every page. Fetching and processing all bugs on every page would be unwise. Cache these stats in memcache. It will be useful to show more stats in future. --- dashboard/app/reporting.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'dashboard/app/reporting.go') diff --git a/dashboard/app/reporting.go b/dashboard/app/reporting.go index da3de2232..23703c78b 100644 --- a/dashboard/app/reporting.go +++ b/dashboard/app/reporting.go @@ -44,9 +44,7 @@ func reportingPollBugs(c context.Context, typ string) []*dashapi.BugReport { log.Errorf(c, "%v", err) return nil } - bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query { - return query.Filter("Status<", BugStatusFixed) - }) + bugs, _, err := loadOpenBugs(c) if err != nil { log.Errorf(c, "%v", err) return nil @@ -150,9 +148,7 @@ func needReport(c context.Context, typ string, state *ReportingState, bug *Bug) } func reportingPollNotifications(c context.Context, typ string) []*dashapi.BugNotification { - bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query { - return query.Filter("Status<", BugStatusFixed) - }) + bugs, _, err := loadOpenBugs(c) if err != nil { log.Errorf(c, "%v", err) return nil @@ -549,6 +545,18 @@ func loadAllBugs(c context.Context, filter func(*db.Query) *db.Query) ([]*Bug, [ return bugs, keys, nil } +func loadNamespaceBugs(c context.Context, ns string) ([]*Bug, []*db.Key, error) { + return loadAllBugs(c, func(query *db.Query) *db.Query { + return query.Filter("Namespace=", ns) + }) +} + +func loadOpenBugs(c context.Context) ([]*Bug, []*db.Key, error) { + return loadAllBugs(c, func(query *db.Query) *db.Query { + return query.Filter("Status<", BugStatusFixed) + }) +} + func foreachBug(c context.Context, filter func(*db.Query) *db.Query, fn func(bug *Bug, key *db.Key) error) error { const batchSize = 1000 var cursor *db.Cursor -- cgit mrf-deployment