From c4b8ccfda19c10d92270af337ffa4dc1e5413a3b Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 19 Sep 2022 13:26:03 +0000 Subject: dashboard: solve the N+1 query problem Do not query crashes from inside needReport, because it's not really needed there and because we query it for each opened bug on the main page. --- dashboard/app/main.go | 2 +- dashboard/app/reporting.go | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dashboard/app/main.go b/dashboard/app/main.go index 5074f118b..f8e2715eb 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -888,7 +888,7 @@ func createUIBug(c context.Context, bug *Bug, state *ReportingState, managers [] var reported time.Time var err error if bug.Status == BugStatusOpen { - _, _, _, _, reportingIdx, status, link, err = needReport(c, "", state, bug) + _, _, reportingIdx, status, link, err = needReport(c, "", state, bug) reported = bug.Reporting[reportingIdx].Reported if err != nil { status = err.Error() diff --git a/dashboard/app/reporting.go b/dashboard/app/reporting.go index 641af4e51..1231078c8 100644 --- a/dashboard/app/reporting.go +++ b/dashboard/app/reporting.go @@ -75,10 +75,16 @@ func reportingPollBugs(c context.Context, typ string) []*dashapi.BugReport { func handleReportBug(c context.Context, typ string, state *ReportingState, bug *Bug) ( *dashapi.BugReport, error) { - reporting, bugReporting, crash, crashKey, _, _, _, err := needReport(c, typ, state, bug) + reporting, bugReporting, _, _, _, err := needReport(c, typ, state, bug) if err != nil || reporting == nil { return nil, err } + crash, crashKey, err := findCrashForBug(c, bug) + if err != nil { + return nil, err + } else if crash == nil { + return nil, fmt.Errorf("no crashes") + } rep, err := createBugReport(c, bug, crash, crashKey, bugReporting, reporting) if err != nil { return nil, err @@ -88,8 +94,8 @@ func handleReportBug(c context.Context, typ string, state *ReportingState, bug * } func needReport(c context.Context, typ string, state *ReportingState, bug *Bug) ( - reporting *Reporting, bugReporting *BugReporting, crash *Crash, - crashKey *db.Key, reportingIdx int, status, link string, err error) { + reporting *Reporting, bugReporting *BugReporting, reportingIdx int, + status, link string, err error) { reporting, bugReporting, reportingIdx, status, err = currentReporting(c, bug) if err != nil || reporting == nil { return @@ -124,9 +130,7 @@ func needReport(c context.Context, typ string, state *ReportingState, bug *Bug) reporting, bugReporting = nil, nil return } - - crash, crashKey, err = findCrashForBug(c, bug) - if err != nil { + if bug.NumCrashes == 0 { status = fmt.Sprintf("%v: no crashes!", reporting.DisplayTitle) reporting, bugReporting = nil, nil return -- cgit mrf-deployment