| 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
|
| +}
|
|
|