Skip to content

Commit

Permalink
WIP/FIXUP
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Feb 15, 2022
1 parent 178eef2 commit c2351e2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
21 changes: 18 additions & 3 deletions core/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,26 @@ func (k HeadStoreKey) ToDS() ds.Key {
func (k DataStoreKey) PrefixEnd() DataStoreKey {
newKey := k

if len(k.DocKey) == 0 {
if k.InstanceType != "" {
newKey.InstanceType = InstanceType(bytesPrefixEnd([]byte(k.InstanceType)))
return newKey
}
if k.FieldId != "" {
newKey.FieldId = string(bytesPrefixEnd([]byte(k.FieldId)))
return newKey
}
if k.DocKey != "" {
newKey.DocKey = string(bytesPrefixEnd([]byte(k.DocKey)))
return newKey
}
if k.IndexId != "" {
newKey.IndexId = string(bytesPrefixEnd([]byte(k.IndexId)))
return newKey
}
if k.CollectionId != "" {
newKey.CollectionId = string(bytesPrefixEnd([]byte(k.CollectionId)))
return newKey
}

newKey.DocKey = string(bytesPrefixEnd([]byte(k.DocKey)))
return newKey
}

Expand Down
14 changes: 9 additions & 5 deletions db/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ type DocumentFetcher struct {
decodedDoc *document.Document
initialized bool

kv *core.KeyValue
kvIter iterable.Iterator
kvResultsIter dsq.Results
kvEnd bool
// kvIndex int
kv *core.KeyValue
kvIter iterable.Iterator
kvResultsIter dsq.Results
kvEnd bool
isReadingDocument bool
}

Expand All @@ -77,6 +76,7 @@ func (df *DocumentFetcher) Init(col *base.CollectionDescription, index *base.Ind
df.fields = fields
df.reverse = reverse
df.initialized = true
df.isReadingDocument = false
df.doc = new(document.EncodedDocument)
df.doc.Schema = &col.Schema

Expand Down Expand Up @@ -390,5 +390,9 @@ func (df *DocumentFetcher) Close() error {
return err
}

if df.kvResultsIter == nil {
return nil
}

return df.kvResultsIter.Close()
}
6 changes: 3 additions & 3 deletions db/fetcher/versioned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
"points": 99.9,
},
// cid: "QmPgnQvhPuLGwVU4ZEcbRy7RNCxSkeS72eKwXusUrAEEXR",
cid: "bafybeihlfvqiwtdpzzxjlsvkxv5ignjgdqer5gwe2pgo5wr5qj4k4dqfjq",
cid: "bafybeienkr6hj73uwd5vhxehavbu26mkk4tv4yd4xefjsa2xy5wlafpls4",
},
{
payload: []byte(`{
Expand All @@ -72,7 +72,7 @@ var (
"age": 22,
},
// cid: "QmRpMfTzExGrXat5W9uCAEtnSpRTvWBcd1hBYNWVPdN9Xh",
cid: "bafybeigwekvyc3lmrtqyxrxh5dgd3n5wl5ljhbwvl2eqmlznzuxhiryo7q",
cid: "bafybeif24w2yjzkb45kywubghcj2pacrfwjjolqq3k3qyiciclvoxcycxe",
},
{
payload: []byte(`{
Expand All @@ -85,7 +85,7 @@ var (
"points": 129.99,
},
// cid: "QmRWYwKadjWqHLrzPKd7MdS4EoQuT2RzWVTaBxxVkeSjFH",
cid: "bafybeibaollpiaq7x2etrsrhbxxwpqyddeaf6njqblo7rrg5on4zv3w45q",
cid: "bafybeiasb5jvqygubz54bp2c7wryj643osthoqgzismc6p53wriq3bpubq",
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion db/tests/query/simple/with_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestQuerySimpleWithEmbeddedLatestCommit(t *testing.T) {
"Age": uint64(21),
"_version": []map[string]interface{}{
{
"cid": "bafybeiercmxn6e3qryxvuped5pplg733c5fj6gjypj5wykk63ouvcfb25m",
"cid": "bafybeibbpmufrnx2zyl66xcxcas25ztyihtkguhtaevyqt72syvplooube",
"links": []map[string]interface{}{
{
"cid": "bafybeiftyjqxyzqtfpi65kde4hla4xm3v4dvtr7fr2p2p5ng5lfg7rrcve",
Expand Down
21 changes: 20 additions & 1 deletion store/wrappedStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func (w *wrappedStore) Delete(ctx context.Context, key ds.Key) error {
}

func (w *wrappedStore) GetIterator(q query.Query) (iterable.Iterator, error) {
return w.store.GetIterator(withPrefix(q, w.transform.ConvertKey(ds.NewKey(q.Prefix)).String()))
iterator, err := w.store.GetIterator(withPrefix(q, w.transform.ConvertKey(ds.NewKey(q.Prefix)).String()))
if err != nil {
return nil, err
}
return &wrappedIterator{transform: w.transform, iterator: iterator}, nil
}

func withPrefix(q query.Query, prefix string) query.Query {
Expand Down Expand Up @@ -198,3 +202,18 @@ orders:
}
return
}

type wrappedIterator struct {
transform ktds.KeyTransform
iterator iterable.Iterator
}

var _ iterable.Iterator = (*wrappedIterator)(nil)

func (w *wrappedIterator) IteratePrefix(ctx context.Context, startPrefix ds.Key, endPrefix ds.Key) (dsq.Results, error) {
return w.iterator.IteratePrefix(ctx, w.transform.ConvertKey(startPrefix), w.transform.ConvertKey(endPrefix))
}

func (w *wrappedIterator) Close() error {
return w.iterator.Close()
}

0 comments on commit c2351e2

Please sign in to comment.