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

Side by Side Diff: impl/memory/datastore_data.go

Issue 2342063003: Differentiate between single- and multi- props. (Closed)
Patch Set: Slice is now always a clone. This is marginally worse performance, but a much safer UI. Created 4 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 | « impl/cloud/datastore_test.go ('k') | impl/memory/datastore_index.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "strings" 10 "strings"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 func rootIDsKey(kind string) []byte { 186 func rootIDsKey(kind string) []byte {
187 return keyBytes(ds.NewKey("", "", "__entity_root_ids__", kind, 0, nil)) 187 return keyBytes(ds.NewKey("", "", "__entity_root_ids__", kind, 0, nil))
188 } 188 }
189 189
190 func curVersion(ents memCollection, key []byte) int64 { 190 func curVersion(ents memCollection, key []byte) int64 {
191 if ents != nil { 191 if ents != nil {
192 if v := ents.Get(key); v != nil { 192 if v := ents.Get(key); v != nil {
193 pm, err := rpm(v) 193 pm, err := rpm(v)
194 memoryCorruption(err) 194 memoryCorruption(err)
195 195
196 » » » pl, ok := pm["__version__"] 196 » » » pl := pm.Slice("__version__")
197 » » » if ok && len(pl) > 0 && pl[0].Type() == ds.PTInt { 197 » » » if len(pl) > 0 && pl[0].Type() == ds.PTInt {
198 return pl[0].Value().(int64) 198 return pl[0].Value().(int64)
199 } 199 }
200 200
201 memoryCorruption(fmt.Errorf("__version__ property missin g or wrong: %v", pm)) 201 memoryCorruption(fmt.Errorf("__version__ property missin g or wrong: %v", pm))
202 } 202 }
203 } 203 }
204 return 0 204 return 0
205 } 205 }
206 206
207 func incrementLocked(ents memCollection, key []byte, amt int) int64 { 207 func incrementLocked(ents memCollection, key []byte, amt int) int64 {
208 if amt <= 0 { 208 if amt <= 0 {
209 panic(fmt.Errorf("incrementLocked called with bad `amt`: %d", am t)) 209 panic(fmt.Errorf("incrementLocked called with bad `amt`: %d", am t))
210 } 210 }
211 ret := curVersion(ents, key) + 1 211 ret := curVersion(ents, key) + 1
212 ents.Set(key, serialize.ToBytes(ds.PropertyMap{ 212 ents.Set(key, serialize.ToBytes(ds.PropertyMap{
213 » » "__version__": {ds.MkPropertyNI(ret + int64(amt-1))}, 213 » » "__version__": ds.MkPropertyNI(ret + int64(amt-1)),
214 })) 214 }))
215 return ret 215 return ret
216 } 216 }
217 217
218 func (d *dataStoreData) allocateIDs(keys []*ds.Key, cb ds.NewKeyCB) error { 218 func (d *dataStoreData) allocateIDs(keys []*ds.Key, cb ds.NewKeyCB) error {
219 // Map keys by entity type. 219 // Map keys by entity type.
220 entityMap := make(map[string][]int) 220 entityMap := make(map[string][]int)
221 for i, key := range keys { 221 for i, key := range keys {
222 ks := key.String() 222 ks := key.String()
223 entityMap[ks] = append(entityMap[ks], i) 223 entityMap[ks] = append(entityMap[ks], i)
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 620 }
621 return namespaces 621 return namespaces
622 } 622 }
623 623
624 func trimPrefix(v, p string) (string, bool) { 624 func trimPrefix(v, p string) (string, bool) {
625 if strings.HasPrefix(v, p) { 625 if strings.HasPrefix(v, p) {
626 return v[len(p):], true 626 return v[len(p):], true
627 } 627 }
628 return v, false 628 return v, false
629 } 629 }
OLDNEW
« no previous file with comments | « impl/cloud/datastore_test.go ('k') | impl/memory/datastore_index.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698