mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 02:23:32 -04:00
Optimise queries run for creating pagination links
We have been running in to the problem in pallets/flask-sqlalchemy#518 where our page loads very slow when viewing a single page of notifications for a service in the admin app. Tracing this back and using SQL explain analyze I can see that getting the notifications takes about a second but the second query to count how many notifications there are (to work out if there is a next page of pagination) can take up to 100 seconds. As suggested in that issue, we do the pagination ourselves. Our pagination doesn't need us to know exactly how many notifications there are, just whether there are any on the next page and that can be done without running the slow query to count how many notifications in total by using `count_pages=False`. This commit is analagous to https://github.com/alphagov/notifications-api/pull/3391/commits/c68d1a2f2391bf712cfe630f9e753dc51048d395 The only difference is that in that case, the pagination links are used to show prev and/or next links in the admin app. In this case, the pagination links are only used to see if there is a page 2, and if there is, say that we are only showing the first 50 results.
This commit is contained in:
@@ -1067,7 +1067,6 @@ def test_dao_get_notifications_by_recipient_is_limited_to_50_results(sample_temp
|
||||
)
|
||||
|
||||
assert len(results.items) == 50
|
||||
assert results.has_next is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("search_term",
|
||||
|
||||
Reference in New Issue
Block a user