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

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

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
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 unified diff | Download patch
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 memory 5 package memory
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "sort" 10 "sort"
11 11
12 ds "github.com/luci/gae/service/datastore" 12 ds "github.com/luci/gae/service/datastore"
13 "github.com/luci/gae/service/datastore/serialize" 13 "github.com/luci/gae/service/datastore/serialize"
14 "github.com/luci/gkvlite" 14 "github.com/luci/gkvlite"
15 ) 15 )
16 16
17 var indexCreationDeterministic = false
18
19 type qIndexSlice []*ds.IndexDefinition 17 type qIndexSlice []*ds.IndexDefinition
20 18
21 func (s qIndexSlice) Len() int { return len(s) } 19 func (s qIndexSlice) Len() int { return len(s) }
22 func (s qIndexSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 20 func (s qIndexSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
23 func (s qIndexSlice) Less(i, j int) bool { return s[i].Less(s[j]) } 21 func (s qIndexSlice) Less(i, j int) bool { return s[i].Less(s[j]) }
24 22
25 func defaultIndicies(kind string, pmap ds.PropertyMap) []*ds.IndexDefinition { 23 func defaultIndicies(kind string, pmap ds.PropertyMap) []*ds.IndexDefinition {
26 ret := make(qIndexSlice, 0, 2*len(pmap)+1) 24 ret := make(qIndexSlice, 0, 2*len(pmap)+1)
27 ret = append(ret, &ds.IndexDefinition{Kind: kind}) 25 ret = append(ret, &ds.IndexDefinition{Kind: kind})
28 for name, pvals := range pmap { 26 for name, pvals := range pmap {
29 needsIndex := false 27 needsIndex := false
30 for _, v := range pvals { 28 for _, v := range pvals {
31 if v.IndexSetting() == ds.ShouldIndex { 29 if v.IndexSetting() == ds.ShouldIndex {
32 needsIndex = true 30 needsIndex = true
33 break 31 break
34 } 32 }
35 } 33 }
36 if !needsIndex { 34 if !needsIndex {
37 continue 35 continue
38 } 36 }
39 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name}}}) 37 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name}}})
40 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name, Direction: ds.DESCENDING}}}) 38 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name, Direction: ds.DESCENDING}}})
41 } 39 }
42 » if indexCreationDeterministic { 40 » if serializationDeterministic {
43 sort.Sort(ret) 41 sort.Sort(ret)
44 } 42 }
45 return ret 43 return ret
46 } 44 }
47 45
48 func indexEntriesWithBuiltins(k ds.Key, pm ds.PropertyMap, complexIdxs []*ds.Ind exDefinition) *memStore { 46 func indexEntriesWithBuiltins(k ds.Key, pm ds.PropertyMap, complexIdxs []*ds.Ind exDefinition) *memStore {
49 sip := partiallySerialize(pm) 47 sip := partiallySerialize(pm)
50 return sip.indexEntries(k, append(defaultIndicies(k.Kind(), pm), complex Idxs...)) 48 return sip.indexEntries(k, append(defaultIndicies(k.Kind(), pm), complex Idxs...))
51 } 49 }
52 50
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 306 }
309 307
310 func updateIndicies(store *memStore, key ds.Key, oldEnt, newEnt ds.PropertyMap) { 308 func updateIndicies(store *memStore, key ds.Key, oldEnt, newEnt ds.PropertyMap) {
311 // load all current complex query index definitions. 309 // load all current complex query index definitions.
312 compIdx := getCompIdxs(getIdxColl(store)) 310 compIdx := getCompIdxs(getIdxColl(store))
313 311
314 mergeIndexes(key.Namespace(), store, 312 mergeIndexes(key.Namespace(), store,
315 indexEntriesWithBuiltins(key, oldEnt, compIdx), 313 indexEntriesWithBuiltins(key, oldEnt, compIdx),
316 indexEntriesWithBuiltins(key, newEnt, compIdx)) 314 indexEntriesWithBuiltins(key, newEnt, compIdx))
317 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698