flask-sqlalchemy icon indicating copy to clipboard operation
flask-sqlalchemy copied to clipboard

Make paginate more efficient with many pages.

Open dourvaris opened this issue 8 years ago • 1 comments

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.

dourvaris avatar May 02 '16 00:05 dourvaris

Is there any interest in this pr at all?

dourvaris avatar Feb 22 '17 11:02 dourvaris

fixed in #1087

davidism avatar Sep 18 '22 16:09 davidism