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

Unified Diff: service/datastore/properties.go

Issue 1269113005: A transparent cache for datastore, backed by memcache. (Closed) Base URL: https://github.com/luci/gae.git@add_meta
Patch Set: Created 5 years, 4 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
Index: service/datastore/properties.go
diff --git a/service/datastore/properties.go b/service/datastore/properties.go
index dfa91515cca6432f38b102d2a119ca230e3655b5..b614920f84494f8cee4bea389b55049d25576fb9 100644
--- a/service/datastore/properties.go
+++ b/service/datastore/properties.go
@@ -414,7 +414,7 @@ func (pm PropertyMap) Save(withMeta bool) (PropertyMap, error) {
}
ret := make(PropertyMap, len(pm))
for k, v := range pm {
- if withMeta || len(k) == 0 || k[0] != '$' {
+ if withMeta || !isMetaKey(k) {
ret[k] = append(ret[k], v...)
}
}
@@ -450,3 +450,21 @@ func (pm PropertyMap) SetMeta(key string, val interface{}) error {
func (pm PropertyMap) Problem() error {
return nil
}
+
+// DataLen returns the number of non-metadata rows in this PropertyMap.
+func (pm PropertyMap) DataLen() int {
+ ret := 0
+ for k := range pm {
+ if isMetaKey(k) {
+ continue
+ }
+ ret++
+ }
+ return ret
+}
+
+func isMetaKey(k string) bool {
+ // empty counts as a metakey since it's not a valid data key, but it's
+ // not really a valid metakey either.
+ return k == "" || k[0] == '$'
+}

Powered by Google App Engine
This is Rietveld 408576698