OLD | NEW |
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 "github.com/luci/luci-go/common/stringset" |
15 ) | 16 ) |
16 | 17 |
17 type qIndexSlice []*ds.IndexDefinition | 18 type qIndexSlice []*ds.IndexDefinition |
18 | 19 |
19 func (s qIndexSlice) Len() int { return len(s) } | 20 func (s qIndexSlice) Len() int { return len(s) } |
20 func (s qIndexSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | 21 func (s qIndexSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
21 func (s qIndexSlice) Less(i, j int) bool { return s[i].Less(s[j]) } | 22 func (s qIndexSlice) Less(i, j int) bool { return s[i].Less(s[j]) } |
22 | 23 |
23 func defaultIndexes(kind string, pmap ds.PropertyMap) []*ds.IndexDefinition { | 24 func defaultIndexes(kind string, pmap ds.PropertyMap) []*ds.IndexDefinition { |
24 ret := make(qIndexSlice, 0, 2*len(pmap)+1) | 25 ret := make(qIndexSlice, 0, 2*len(pmap)+1) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 type serializedIndexablePmap map[string]serializedPvals | 62 type serializedIndexablePmap map[string]serializedPvals |
62 | 63 |
63 func partiallySerialize(k ds.Key, pm ds.PropertyMap) (ret serializedIndexablePma
p) { | 64 func partiallySerialize(k ds.Key, pm ds.PropertyMap) (ret serializedIndexablePma
p) { |
64 ret = make(serializedIndexablePmap, len(pm)+2) | 65 ret = make(serializedIndexablePmap, len(pm)+2) |
65 ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))} | 66 ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))} |
66 for k != nil { | 67 for k != nil { |
67 ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBy
tes(ds.MkProperty(k))) | 68 ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBy
tes(ds.MkProperty(k))) |
68 k = k.Parent() | 69 k = k.Parent() |
69 } | 70 } |
70 for k, vals := range pm { | 71 for k, vals := range pm { |
71 » » dups := stringSet{} | 72 » » dups := stringset.New(0) |
72 newVals := make(serializedPvals, 0, len(vals)) | 73 newVals := make(serializedPvals, 0, len(vals)) |
73 for _, v := range vals { | 74 for _, v := range vals { |
74 if v.IndexSetting() == ds.NoIndex { | 75 if v.IndexSetting() == ds.NoIndex { |
75 continue | 76 continue |
76 } | 77 } |
77 data := serialize.ToBytes(v) | 78 data := serialize.ToBytes(v) |
78 dataS := string(data) | 79 dataS := string(data) |
79 » » » if !dups.add(dataS) { | 80 » » » if !dups.Add(dataS) { |
80 continue | 81 continue |
81 } | 82 } |
82 newVals = append(newVals, data) | 83 newVals = append(newVals, data) |
83 } | 84 } |
84 if len(newVals) > 0 { | 85 if len(newVals) > 0 { |
85 ret[k] = newVals | 86 ret[k] = newVals |
86 } | 87 } |
87 } | 88 } |
88 return | 89 return |
89 } | 90 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 compIdx := []*ds.IndexDefinition{} | 298 compIdx := []*ds.IndexDefinition{} |
298 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { | 299 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { |
299 compIdx = append(compIdx, i) | 300 compIdx = append(compIdx, i) |
300 return true | 301 return true |
301 }) | 302 }) |
302 | 303 |
303 mergeIndexes(key.Namespace(), store, | 304 mergeIndexes(key.Namespace(), store, |
304 indexEntriesWithBuiltins(key, oldEnt, compIdx), | 305 indexEntriesWithBuiltins(key, oldEnt, compIdx), |
305 indexEntriesWithBuiltins(key, newEnt, compIdx)) | 306 indexEntriesWithBuiltins(key, newEnt, compIdx)) |
306 } | 307 } |
OLD | NEW |