Skip to content

Commit

Permalink
Merge pull request #44 from ipfs/fix/datastore-order
Browse files Browse the repository at this point in the history
fix application or ordering for interface change
  • Loading branch information
Stebalien authored Jan 24, 2019
2 parents 4a09354 + 8c2262c commit 0b833ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ func (t *txn) Query(q dsq.Query) (dsq.Results, error) {
opt := badger.DefaultIteratorOptions
opt.PrefetchValues = !q.KeysOnly

// Special case order by key.
orders := q.Orders
if len(orders) > 0 {
switch q.Orders[0].(type) {
case dsq.OrderByKey, *dsq.OrderByKey:
// Already ordered by key.
orders = nil
case dsq.OrderByKeyDescending, *dsq.OrderByKeyDescending:
orders = nil
opt.Reverse = true
}
}

txn := t.txn

it := txn.NewIterator(opt)
Expand Down Expand Up @@ -339,8 +352,8 @@ func (t *txn) Query(q dsq.Query) (dsq.Results, error) {
for _, f := range q.Filters {
qr = dsq.NaiveFilter(qr, f)
}
for _, o := range q.Orders {
qr = dsq.NaiveOrder(qr, o)
if len(orders) > 0 {
qr = dsq.NaiveOrder(qr, orders...)
}

return qr, nil
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
{
"author": "jbenet",
"hash": "Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM",
"hash": "QmPGYyi1DtuWyUkG3PtvLz1xb4ScjnUvwJMCoX3cxeyxNr",
"name": "go-datastore",
"version": "3.4.1"
"version": "3.5.0"
},
{
"author": "dgraph-io",
Expand Down

0 comments on commit 0b833ba

Please sign in to comment.