Make new query for children

parent 16330520
...@@ -220,18 +220,20 @@ func (d *Datastore) Delete(key ds.Key) error { ...@@ -220,18 +220,20 @@ func (d *Datastore) Delete(key ds.Key) error {
return cds.Delete(k) return cds.Delete(k)
} }
func (d *Datastore) Query(q query.Query) (query.Results, error) { func (d *Datastore) Query(master query.Query) (query.Results, error) {
prefix := ds.NewKey(q.Prefix) childQuery := query.Query{
dses, mounts, rests := d.lookupAll(prefix) Prefix: master.Prefix,
Limit: master.Limit,
Orders: master.Orders,
KeysOnly: master.KeysOnly,
ReturnExpirations: master.ReturnExpirations,
}
// offset needs to be applied after the results are aggregated prefix := ds.NewKey(childQuery.Prefix)
offset := q.Offset dses, mounts, rests := d.lookupAll(prefix)
q.Offset = 0
filters := q.Filters
q.Filters = []query.Filter{}
queries := &querySet{ queries := &querySet{
query: q, query: childQuery,
heads: make([]*queryResults, 0, len(dses)), heads: make([]*queryResults, 0, len(dses)),
} }
...@@ -240,7 +242,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -240,7 +242,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
dstore := dses[i] dstore := dses[i]
rest := rests[i] rest := rests[i]
qi := q qi := childQuery
qi.Prefix = rest.String() qi.Prefix = rest.String()
results, err := dstore.Query(qi) results, err := dstore.Query(qi)
...@@ -251,23 +253,23 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -251,23 +253,23 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
queries.addResults(mount, results) queries.addResults(mount, results)
} }
qr := query.ResultsFromIterator(q, query.Iterator{ qr := query.ResultsFromIterator(childQuery, query.Iterator{
Next: queries.next, Next: queries.next,
Close: queries.close, Close: queries.close,
}) })
if len(filters) > 0 { if len(master.Filters) > 0 {
for _, f := range filters { for _, f := range master.Filters {
qr = query.NaiveFilter(qr, f) qr = query.NaiveFilter(qr, f)
} }
} }
if offset > 0 { if master.Offset > 0 {
qr = query.NaiveOffset(qr, offset) qr = query.NaiveOffset(qr, master.Offset)
} }
if q.Limit > 0 { if childQuery.Limit > 0 {
qr = query.NaiveLimit(qr, q.Limit) qr = query.NaiveLimit(qr, childQuery.Limit)
} }
return qr, nil return qr, nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment