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

Unified Diff: impl/prod/raw_datastore_type_converter.go

Issue 2342063003: Differentiate between single- and multi- props. (Closed)
Patch Set: Slice is now always a clone. This is marginally worse performance, but a much safer UI. Created 4 years, 3 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 | « impl/prod/everything_test.go ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/prod/raw_datastore_type_converter.go
diff --git a/impl/prod/raw_datastore_type_converter.go b/impl/prod/raw_datastore_type_converter.go
index 9799d577233b0c6f3ccc69498fd61ca41ad180f2..24bb6f4fa54deffa7336c37495785dd4947487ac 100644
--- a/impl/prod/raw_datastore_type_converter.go
+++ b/impl/prod/raw_datastore_type_converter.go
@@ -162,19 +162,48 @@ func (tf *typeFilter) Load(props []datastore.Property) error {
if err != nil {
return err
}
- tf.pm[p.Name] = append(tf.pm[p.Name], prop)
+
+ pdata := tf.pm[p.Name]
+ if p.Multiple {
+ var pslice ds.PropertySlice
+ if pdata != nil {
+ var ok bool
+ if pslice, ok = pdata.(ds.PropertySlice); !ok {
+ return fmt.Errorf("mixed Multiple/non-Multiple properties for %q", p.Name)
+ }
+ }
+ tf.pm[p.Name] = append(pslice, prop)
+ } else {
+ if pdata != nil {
+ return fmt.Errorf("multiple properties for non-Multiple %q", p.Name)
+ }
+ tf.pm[p.Name] = prop
+ }
}
return nil
}
func (tf *typeFilter) Save() ([]datastore.Property, error) {
props := []datastore.Property{}
- for name, propList := range tf.pm {
+ for name, pdata := range tf.pm {
if len(name) != 0 && name[0] == '$' {
continue
}
- multiple := len(propList) > 1
- for _, prop := range propList {
+
+ var (
+ pslice ds.PropertySlice
+ multiple bool
+ )
+ switch t := pdata.(type) {
+ case ds.Property:
+ pslice = ds.PropertySlice{t}
+ case ds.PropertySlice:
+ pslice, multiple = t, true
+ default:
+ return nil, fmt.Errorf("unknown PropertyData type %T", t)
+ }
+
+ for _, prop := range pslice {
toAdd, err := dsF2RProp(tf.ctx, prop)
if err != nil {
return nil, err
« no previous file with comments | « impl/prod/everything_test.go ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698