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

Unified Diff: impl/memory/datastore_index.go

Issue 1336443003: Implement projection queries correctly. (Closed) Base URL: https://github.com/luci/gae.git@master
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | impl/memory/datastore_index_test.go » ('j') | impl/memory/datastore_index_test.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_index.go
diff --git a/impl/memory/datastore_index.go b/impl/memory/datastore_index.go
index f4db119e6bd8af872caa037749419d62181a2e38..e61ce89d770c411f89df47ca34d3aa25719bad6e 100644
--- a/impl/memory/datastore_index.go
+++ b/impl/memory/datastore_index.go
@@ -60,27 +60,36 @@ func (s serializedPvals) Less(i, j int) bool { return bytes.Compare(s[i], s[j])
// the ancestor entries for this key.
type serializedIndexablePmap map[string]serializedPvals
+func serializeRow(vals []ds.Property) serializedPvals {
iannucci 2015/09/10 03:56:58 This was a convenient refactoring. It'll become mo
+ dups := map[string]struct{}{}
+ ret := make(serializedPvals, 0, len(vals))
+ for _, v := range vals {
+ if v.IndexSetting() == ds.NoIndex {
+ continue
+ }
+ data := serialize.ToBytes(v.ForIndex())
+ dataS := string(data)
+ if _, ok := dups[dataS]; ok {
+ continue
+ }
+ dups[dataS] = struct{}{}
+ ret = append(ret, data)
+ }
+ return ret
+}
+
func partiallySerialize(k ds.Key, pm ds.PropertyMap) (ret serializedIndexablePmap) {
ret = make(serializedIndexablePmap, len(pm)+2)
+ if k == nil {
+ impossible(fmt.Errorf("key to partiallySerialize is nil"))
+ }
ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))}
for k != nil {
ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBytes(ds.MkProperty(k)))
k = k.Parent()
}
for k, vals := range pm {
- dups := stringSet{}
- newVals := make(serializedPvals, 0, len(vals))
- for _, v := range vals {
- if v.IndexSetting() == ds.NoIndex {
- continue
- }
- data := serialize.ToBytes(v)
- dataS := string(data)
- if !dups.add(dataS) {
- continue
- }
- newVals = append(newVals, data)
- }
+ newVals := serializeRow(vals)
if len(newVals) > 0 {
ret[k] = newVals
}
« no previous file with comments | « no previous file | impl/memory/datastore_index_test.go » ('j') | impl/memory/datastore_index_test.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698