Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: appengine/logdog/coordinator/hierarchy/hierarchy.go

Issue 1883593005: LogDog: Only create missing hierarchy components. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/logdog/coordinator/hierarchy/hierarchy.go
diff --git a/appengine/logdog/coordinator/hierarchy/hierarchy.go b/appengine/logdog/coordinator/hierarchy/hierarchy.go
index 60acb70701f99004dc4a9fde3f58186a7b979658..81f5d59c0ca6429b85e827322d18444a58276b35 100644
--- a/appengine/logdog/coordinator/hierarchy/hierarchy.go
+++ b/appengine/logdog/coordinator/hierarchy/hierarchy.go
@@ -251,7 +251,31 @@ func Put(di ds.Interface, p types.StreamPath) error {
components = append(components, &cur)
}
- return di.PutMulti(components)
+
+ // See if any components are already registered.
+ exists := make([]*ds.Key, len(components))
+ for i, c := range components {
+ exists[i] = di.KeyForObj(c)
+ }
+ bl, err := di.ExistsMulti(exists)
+ if err != nil {
+ return err
+ }
+
+ // Only create entities that don't already exist.
+ create := make([]*componentEntity, 0, len(components))
+ for i, b := range bl {
+ if !b {
+ create = append(create, components[i])
+ }
+ }
+
+ if len(create) > 0 {
+ if err := di.PutMulti(create); err != nil {
+ return err
+ }
+ }
+ return nil
}
// MarkPurged sets the named path component's purged status to v.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698