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

Unified Diff: impl/memory/datastore_index.go

Issue 1292913002: Split off serialization and key functions to their own packages. (Closed) Base URL: https://github.com/luci/gae.git@make_queries_better
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/datastore_data.go ('k') | impl/memory/datastore_query.go » ('j') | no next file with comments »
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 1fb4c0ea95727ee1cdd0becb7c4e788d7ed4ac53..f22a970a8e9ef62593c2b60be332c08bd98086b6 100644
--- a/impl/memory/datastore_index.go
+++ b/impl/memory/datastore_index.go
@@ -10,6 +10,7 @@ import (
"sort"
ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/datastore/serialize"
"github.com/luci/gkvlite"
)
@@ -73,7 +74,7 @@ func partiallySerialize(pm ds.PropertyMap) (ret serializedIndexablePmap) {
continue
}
buf.Reset()
- v.Write(buf, ds.WithoutContext)
+ serialize.WriteProperty(buf, serialize.WithoutContext, v)
newVal := make([]byte, buf.Len())
copy(newVal, buf.Bytes())
newVals = append(newVals, newVal)
@@ -183,16 +184,12 @@ func (sip serializedIndexablePmap) indexEntries(k ds.Key, idxs []*ds.IndexDefini
idxColl := ret.SetCollection("idx", nil)
// getIdxEnts retrieves an index collection or adds it if it's not there.
getIdxEnts := func(qi *ds.IndexDefinition) *memCollection {
- buf := &bytes.Buffer{}
- qi.Write(buf)
- b := buf.Bytes()
+ b := serialize.ToBytes(*qi)
idxColl.Set(b, []byte{})
return ret.SetCollection(fmt.Sprintf("idx:%s:%s", k.Namespace(), b), nil)
}
- buf := &bytes.Buffer{}
- ds.WriteKey(buf, ds.WithoutContext, k)
- keyData := buf.Bytes()
+ keyData := serialize.ToBytes(k)
walkPermutations := func(prefix []byte, irg indexRowGen, ents *memCollection) {
prev := []byte{} // intentionally make a non-nil slice, gkvlite hates nil.
@@ -214,9 +211,7 @@ func (sip serializedIndexablePmap) indexEntries(k ds.Key, idxs []*ds.IndexDefini
idxEnts.Set(keyData, []byte{}) // propless index, e.g. kind -> key = nil
} else if idx.Ancestor {
for ancKey := k; ancKey != nil; ancKey = ancKey.Parent() {
- buf := &bytes.Buffer{}
- ds.WriteKey(buf, ds.WithoutContext, ancKey)
- walkPermutations(buf.Bytes(), irg, idxEnts)
+ walkPermutations(serialize.ToBytes(ancKey), irg, idxEnts)
}
} else {
walkPermutations(nil, irg, idxEnts)
@@ -235,11 +230,11 @@ func getCompIdxs(idxColl *memCollection) []*ds.IndexDefinition {
if !bytes.HasPrefix(i.Key, complexQueryPrefix) {
return false
}
- qi := &ds.IndexDefinition{}
- if err := qi.Read(bytes.NewBuffer(i.Key)); err != nil {
+ qi, err := serialize.ReadIndexDefinition(bytes.NewBuffer(i.Key))
+ if err != nil {
panic(err) // memory corruption
}
- compIdx = append(compIdx, qi)
+ compIdx = append(compIdx, &qi)
return true
})
return compIdx
@@ -304,7 +299,7 @@ func addIndex(store *memStore, ns string, compIdx []*ds.IndexDefinition) {
if err != nil {
panic(err) // memory corruption
}
- k, err := ds.ReadKey(bytes.NewBuffer(i.Key), ds.WithoutContext, globalAppID, ns)
+ k, err := serialize.ReadKey(bytes.NewBuffer(i.Key), serialize.WithoutContext, globalAppID, ns)
if err != nil {
panic(err)
}
« no previous file with comments | « impl/memory/datastore_data.go ('k') | impl/memory/datastore_query.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698