diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-10-02 10:58:05 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-10-02 16:11:47 +0200 |
| commit | 91cd7bce0de561553bdca1a450a5603290a8b01f (patch) | |
| tree | 545982b8f524f4f22f12427bc9b03a7952671b0f | |
| parent | 3297cdf8bb4d530c6c3bdc2111dac112b892fdf9 (diff) | |
dashboard/app: refactor updateBugReportingBatch
Refactor updateBugReportingBatch to be more generic.
Useful helper for other bulk bug updates.
| -rw-r--r-- | dashboard/app/admin.go | 11 |
1 files 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 |
