More efficient way to detect next page#15
Conversation
|
|
||
| def has_next_page(self): | ||
| # Running count() as done in get_pages() can be inefficient for un-indexed queries. | ||
| with_one_more = self.query.paginate(self.get_page(), self.paginate_by + 1) |
There was a problem hiding this comment.
I think this is wrong because it will offset by (page number) * (page size) and this makes the page size bigger
I think what we can do is just fetch the next page with self.query.paginate(self.get_page() + 1, self.paginate_by)
There was a problem hiding this comment.
There was a problem hiding this comment.
oh yes of course! that makes sense
| def has_results_on_next_page(self): | ||
| # Running count() as done in get_pages() can be inefficient for un-indexed queries. | ||
| results = self.query.paginate(self.get_page() + 1, self.paginate_by) | ||
| return len(results) > 0 |
There was a problem hiding this comment.
two nits: I think paginate returns the query object, so results is actually a query and means we can also use exists() here if we want
There was a problem hiding this comment.
this failed tests, so i may just keep it the old way. sorry, just trying to not get tooooo distracted by this
| setup( | ||
| name='flask-peewee', | ||
| version='3.0.5+propel', | ||
| version='3.0.6+propel', |
There was a problem hiding this comment.
Can we make this propel.2 instead of bumping the version, so we can merge the upstream 3.0.6 in the future if it exists?
There was a problem hiding this comment.
oh true. anyway it does exist! he bumped to 3.1.0 like last month
There was a problem hiding this comment.
i'll just stay on 3.0.5+propel, our UV pinning goes by commit hash anyway
Context
We're running a secret inefficient count when loading the Providers User admin page. This should hopefully do this query more efficiently