From 91cd7bce0de561553bdca1a450a5603290a8b01f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 2 Oct 2020 10:58:05 +0200 Subject: dashboard/app: refactor updateBugReportingBatch Refactor updateBugReportingBatch to be more generic. Useful helper for other bulk bug updates. --- dashboard/app/admin.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dashboard/app/admin.go b/dashboard/app/admin.go index 8b2737cdd..104807a56 100644 --- a/dashboard/app/admin.go +++ b/dashboard/app/admin.go @@ -142,6 +142,9 @@ func updateBugReporting(c context.Context, w http.ResponseWriter, r *http.Reques } log.Warningf(c, "fetched %v bugs for namespce %v", len(bugs), ns) cfg := config.Namespaces[ns] + transform := func(bug *Bug) { + createBugReporting(bug, cfg) + } var batchKeys []*db.Key const batchSize = 20 for i, bug := range bugs { @@ -150,28 +153,28 @@ func updateBugReporting(c context.Context, w http.ResponseWriter, r *http.Reques } batchKeys = append(batchKeys, keys[i]) if len(batchKeys) == batchSize { - if err := updateBugReportingBatch(c, cfg, batchKeys); err != nil { + if err := updateBugBatch(c, batchKeys, transform); err != nil { return err } batchKeys = nil } } if len(batchKeys) != 0 { - if err := updateBugReportingBatch(c, cfg, batchKeys); err != nil { + if err := updateBugBatch(c, batchKeys, transform); err != nil { return err } } return nil } -func updateBugReportingBatch(c context.Context, cfg *Config, keys []*db.Key) error { +func updateBugBatch(c context.Context, keys []*db.Key, transform func(bug *Bug)) error { tx := func(c context.Context) error { bugs := make([]*Bug, len(keys)) if err := db.GetMulti(c, keys, bugs); err != nil { return err } for _, bug := range bugs { - createBugReporting(bug, cfg) + transform(bug) } _, err := db.PutMulti(c, keys, bugs) return err -- cgit mrf-deployment