diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-11-01 23:53:42 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-11-01 23:53:42 -0700 |
commit | 3fc8755911eeaf508c5139b8e9b7e4d0f54d046c (patch) | |
tree | 4423ccfe74811d92041b2e468f66c068dd7c7781 | |
parent | 863e88194336a7baefbceb266f56d60d6a002da5 (diff) |
adding some bounds checking to the cursor location based on the expected results
-rw-r--r-- | system/db/content.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/system/db/content.go b/system/db/content.go index 03e6a41..9aa86d8 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -217,17 +217,28 @@ func Query(namespace string, opts QueryOptions) [][]byte { c := b.Cursor() n := b.Stats().KeyN + var start, end int + switch opts.Count { + case -1: + start = 0 + end = n + + default: + start = opts.Count * opts.Offset + end = start + opts.Count + } + i := 0 // count of num posts added cur := 0 // count of where cursor is switch opts.Order { case "asc": for k, v := c.Last(); k != nil; c.Prev() { - if cur < opts.Offset*opts.Count { + if start < cur && cur < end { cur++ continue } - if i >= opts.Count || cur > n { + if i >= opts.Count { break } @@ -237,12 +248,12 @@ func Query(namespace string, opts QueryOptions) [][]byte { case "desc": for k, v := c.First(); k != nil; c.Next() { - if cur < opts.Offset*opts.Count { + if start < cur && cur < end { cur++ continue } - if i >= opts.Count || cur > n { + if i >= opts.Count { break } |