flask-sqlalchemy
flask-sqlalchemy copied to clipboard
Make paginate more efficient with many pages.
Current paginate iterates over every single page possible, and discards most of them, for large page sets > 50,000 this can be quite slow and noticeable.
This patch should make paginating on many pages much faster since it won't iterate over every single page possible, it should make it constant time more or less.
Speed for 100,000 pages:
(old)
In [14]: %timeit list(flask_sqlalchemy.Pagination(None, 4, 10, 1000000, []).iter_pages())
10 loops, best of 3: 81.6 ms per loop
(new)
In [11]: %timeit list(flask_sqlalchemy.Pagination(None, 4, 10, 1000000, []).iter_pages())
100000 loops, best of 3: 11 µs per loop
Also added a bunch of tests for edge cases.
Is there any interest in this pr at all?
fixed in #1087