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

Unified Diff: service/datastore/key.go

Issue 1363063002: Add ability to estimate the size of a PropertyMap (Closed) Base URL: https://github.com/luci/gae.git@minor_tweak
Patch Set: 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 | « no previous file | service/datastore/properties.go » ('j') | service/datastore/properties.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/key.go
diff --git a/service/datastore/key.go b/service/datastore/key.go
index cb3bd0181de13433a6ac53fe04f33655c8768381..d716cc6ea11d6013af9b376bed1e74e2305e5477 100644
--- a/service/datastore/key.go
+++ b/service/datastore/key.go
@@ -410,3 +410,25 @@ func (k *Key) Split() (appID, namespace string, toks []KeyTok) {
copy(toks, k.toks)
return
}
+
+// EstimateSize estimates the size of a Key. If withNamespace is true, then it
+// includes the length of the AppID and Namespace.
+//
+// It uses https://cloud.google.com/appengine/articles/storage_breakdown?csw=1
+// as a guide for these values.
+func (k *Key) EstimateSize(withNamespace bool) int {
+ ret := 0
+ if withNamespace {
+ ret += len(k.appID)
+ ret += len(k.namespace)
+ }
+ for _, t := range k.toks {
+ ret += len(t.Kind)
+ if t.StringID != "" {
+ ret += len(t.StringID)
+ } else {
+ ret += 8
+ }
+ }
+ return ret
+}
« no previous file with comments | « no previous file | service/datastore/properties.go » ('j') | service/datastore/properties.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698