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

Unified Diff: service/datastore/pls_impl.go

Issue 1358743002: Make Get operations only serialize the bare minimum. (Closed) Base URL: https://github.com/luci/gae.git@fix_time
Patch Set: PropertyMap should always copy on save-out functions to avoid external mutation Created 5 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 | « service/datastore/multiarg.go ('k') | service/datastore/pls_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/pls_impl.go
diff --git a/service/datastore/pls_impl.go b/service/datastore/pls_impl.go
index fb39abcf167945f0cf348db29d85bf61d2e42eac..067ed06e325094d37698129a0c3d4fc38505153c 100644
--- a/service/datastore/pls_impl.go
+++ b/service/datastore/pls_impl.go
@@ -205,30 +205,15 @@ func loadInner(codec *structCodec, structValue reflect.Value, index int, name st
}
func (p *structPLS) Save(withMeta bool) (PropertyMap, error) {
- size := len(p.c.byName)
+ ret := PropertyMap(nil)
if withMeta {
- size += len(p.c.byMeta)
+ ret = p.GetAllMeta()
+ } else {
+ ret = make(PropertyMap, len(p.c.byName))
}
- ret := make(PropertyMap, size)
if _, err := p.save(ret, "", ShouldIndex); err != nil {
return nil, err
}
- if withMeta {
- for k := range p.c.byMeta {
- val, err := p.GetMeta(k)
- if err != nil {
- return nil, err // TODO(riannucci): should these be ignored?
- }
- p := Property{}
- if err = p.SetValue(val, NoIndex); err != nil {
- return nil, err
- }
- ret["$"+k] = []Property{p}
- }
- if _, ok := p.c.byMeta["kind"]; !ok {
- ret["$kind"] = []Property{MkPropertyNI(p.getDefaultKind())}
- }
- }
return ret, nil
}
@@ -311,6 +296,10 @@ func (p *structPLS) GetMeta(key string) (interface{}, error) {
}
return nil, ErrMetaFieldUnset
}
+ return p.getMetaFor(idx), nil
+}
+
+func (p *structPLS) getMetaFor(idx int) interface{} {
st := p.c.byIndex[idx]
val := st.metaVal
f := p.o.Field(idx)
@@ -322,7 +311,23 @@ func (p *structPLS) GetMeta(key string) (interface{}, error) {
}
}
}
- return val, nil
+ return val
+}
+
+func (p *structPLS) GetAllMeta() PropertyMap {
+ ret := make(PropertyMap, len(p.c.byMeta)+1)
+ for k, idx := range p.c.byMeta {
+ val := p.getMetaFor(idx)
+ p := Property{}
+ if err := p.SetValue(val, NoIndex); err != nil {
+ continue
+ }
+ ret["$"+k] = []Property{p}
+ }
+ if _, ok := p.c.byMeta["kind"]; !ok {
+ ret["$kind"] = []Property{MkPropertyNI(p.getDefaultKind())}
+ }
+ return ret
}
func (p *structPLS) GetMetaDefault(key string, def interface{}) interface{} {
« no previous file with comments | « service/datastore/multiarg.go ('k') | service/datastore/pls_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698