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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | service/datastore/properties.go » ('j') | service/datastore/properties.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package datastore 5 package datastore
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/base64" 9 "encoding/base64"
10 "encoding/json" 10 "encoding/json"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // 403 //
404 // toks is guaranteed to be empty if and only if k is nil. If k is non-nil then 404 // toks is guaranteed to be empty if and only if k is nil. If k is non-nil then
405 // it contains at least one token. 405 // it contains at least one token.
406 func (k *Key) Split() (appID, namespace string, toks []KeyTok) { 406 func (k *Key) Split() (appID, namespace string, toks []KeyTok) {
407 appID = k.appID 407 appID = k.appID
408 namespace = k.namespace 408 namespace = k.namespace
409 toks = make([]KeyTok, len(k.toks)) 409 toks = make([]KeyTok, len(k.toks))
410 copy(toks, k.toks) 410 copy(toks, k.toks)
411 return 411 return
412 } 412 }
413
414 // EstimateSize estimates the size of a Key. If withNamespace is true, then it
415 // includes the length of the AppID and Namespace.
416 //
417 // It uses https://cloud.google.com/appengine/articles/storage_breakdown?csw=1
418 // as a guide for these values.
419 func (k *Key) EstimateSize(withNamespace bool) int {
420 ret := 0
421 if withNamespace {
422 ret += len(k.appID)
423 ret += len(k.namespace)
424 }
425 for _, t := range k.toks {
426 ret += len(t.Kind)
427 if t.StringID != "" {
428 ret += len(t.StringID)
429 } else {
430 ret += 8
431 }
432 }
433 return ret
434 }
OLDNEW
« 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