diff options
author | Sean McGivern <sean@gitlab.com> | 2016-06-23 14:15:46 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-06-23 15:26:50 +0100 |
commit | d7a5a28c53c3af710ceb8ef4867ea61af7462903 (patch) | |
tree | 23490669737bddbcc2e6ce33a4b598c56cb5d331 /vendor | |
parent | 2de9d66fe44fd98e6ba1264058c642d05a33f2e8 (diff) | |
download | gitlab-ce-d7a5a28c53c3af710ceb8ef4867ea61af7462903.tar.gz |
Fix pagination on sorts with lots of ties
Postgres and MySQL don't guarantee that pagination with `LIMIT` and
`OFFSET` will work if the ordering isn't unique. From the Postgres docs:
> When using `LIMIT`, it is important to use an `ORDER BY` clause that
> constrains the result rows into a unique order. Otherwise you will get
> an unpredictable subset of the query's rows
Before:
[1] pry(main)> issues = 1.upto(Issue.count).map { |i| Issue.sort('priority').page(i).per(1).map(&:id) }.flatten
[2] pry(main)> issues.count
=> 81
[3] pry(main)> issues.uniq.count
=> 42
After:
[1] pry(main)> issues = 1.upto(Issue.count).map { |i| Issue.sort('priority').page(i).per(1).map(&:id) }.flatten
[2] pry(main)> issues.count
=> 81
[3] pry(main)> issues.uniq.count
=> 81
Diffstat (limited to 'vendor')
0 files changed, 0 insertions, 0 deletions