From a8529b82fb3bb45832b08a099e7eb51707da9b37 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 25 Mar 2021 20:01:09 +0100 Subject: dashboard/app: speed up main page We have too many bugs in total now, loading them is very slow. We don't show fixed/invalid bugs on the main page, so don't load them. This requires issuing two separate queries, but it's still much faster than loading all bugs. --- dashboard/app/index.yaml | 5 +++++ dashboard/app/main.go | 52 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/dashboard/app/index.yaml b/dashboard/app/index.yaml index eef631a55..607611bc7 100644 --- a/dashboard/app/index.yaml +++ b/dashboard/app/index.yaml @@ -19,6 +19,11 @@ indexes: - name: Status - name: HappenedOn +- kind: Bug + properties: + - name: HappenedOn + - name: Status + - kind: Bug properties: - name: Namespace diff --git a/dashboard/app/main.go b/dashboard/app/main.go index a7681c55b..e531b808a 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -553,14 +553,7 @@ func textFilename(tag string) string { } func fetchNamespaceBugs(c context.Context, accessLevel AccessLevel, ns, manager string) ([]*uiBugGroup, error) { - filter := func(query *db.Query) *db.Query { - query = query.Filter("Namespace=", ns) - if manager != "" { - query = query.Filter("HappenedOn=", manager) - } - return query - } - bugs, _, err := loadAllBugs(c, filter) + bugs, err := loadVisibleBugs(c, accessLevel, ns, manager) if err != nil { return nil, err } @@ -576,9 +569,6 @@ func fetchNamespaceBugs(c context.Context, accessLevel AccessLevel, ns, manager bugMap := make(map[string]*uiBug) var dups []*Bug for _, bug := range bugs { - if bug.Status == BugStatusFixed || bug.Status == BugStatusInvalid { - continue - } if accessLevel < bug.sanitizeAccess(accessLevel) { continue } @@ -642,6 +632,46 @@ func fetchNamespaceBugs(c context.Context, accessLevel AccessLevel, ns, manager return uiGroups, nil } +func loadVisibleBugs(c context.Context, accessLevel AccessLevel, ns, manager string) ([]*Bug, error) { + // Load open and dup bugs in in 2 separate queries. + // Ideally we load them in one query with a suitable filter, + // but unfortunately status values don't allow one query (BugStatusInvalid). + // Ideally we also have separate status for "dup of a closed bug" as we don't need to fetch them. + // Potentially changing "dup" to "dup of a closed bug" can be done in background. + // But 2 queries is still much faster than fetching all bugs and we can do this in parallel. + errc := make(chan error) + var dups []*Bug + go func() { + filter := func(query *db.Query) *db.Query { + query = query.Filter("Namespace=", ns). + Filter("Status=", BugStatusDup) + if manager != "" { + query = query.Filter("HappenedOn=", manager) + } + return query + } + var err error + dups, _, err = loadAllBugs(c, filter) + errc <- err + }() + filter := func(query *db.Query) *db.Query { + query = query.Filter("Namespace=", ns). + Filter("Status<", BugStatusFixed) + if manager != "" { + query = query.Filter("HappenedOn=", manager) + } + return query + } + bugs, _, err := loadAllBugs(c, filter) + if err != nil { + return nil, err + } + if err := <-errc; err != nil { + return nil, err + } + return append(bugs, dups...), nil +} + func fetchTerminalBugs(c context.Context, accessLevel AccessLevel, ns, manager string, typ *TerminalBug) (*uiBugGroup, error) { bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query { -- cgit mrf-deployment