aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-09-19 13:26:03 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-09-20 10:35:50 +0200
commitc4b8ccfda19c10d92270af337ffa4dc1e5413a3b (patch)
tree88a1f8caa837dea64accda94e7b1be1ef5be4b9c
parent7c41a9ba554969dd7b2ed8136cff49147972e122 (diff)
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.
-rw-r--r--dashboard/app/main.go2
-rw-r--r--dashboard/app/reporting.go16
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