Skip to content

Commit

Permalink
docstore/memdocstore: apply limit after sorting (#2978)
Browse files Browse the repository at this point in the history
Fixes #2977

Co-authored-by: Robert van Gent <[email protected]>
  • Loading branch information
jba and vangent authored Mar 16, 2021
1 parent 32ad8e5 commit db7a6e7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docstore/memdocstore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ func (c *collection) RunGetQuery(_ context.Context, q *driver.Query) (driver.Doc

var resultDocs []storedDoc
for _, doc := range c.docs {
if q.Limit > 0 && len(resultDocs) == q.Limit {
break
}
if filtersMatch(q.Filters, doc) {
resultDocs = append(resultDocs, doc)
}
}
if q.OrderByField != "" {
sortDocs(resultDocs, q.OrderByField, q.OrderAscending)
}

if q.Limit > 0 && len(resultDocs) > q.Limit {
resultDocs = resultDocs[:q.Limit]
}

// Include the key field in the field paths if there is one.
var fps [][]string
if len(q.FieldPaths) > 0 && c.keyField != "" {
Expand Down

0 comments on commit db7a6e7

Please sign in to comment.