Don't return pagination links for API Message log requests

Flask-SQLAlchemy paginate function issues a separate query to get
the total count of rows for a given filter. This query (with
filters used by the API integration Message log page) is slow for
services with large number of notifications.

Since Message log page doesn't actually allow users to paginate
through the response (it only shows the last 50 messages) we can
use limit instead of paginate, which requires passing in another
flag from admin to the dao method.

`count` flag has been added to `paginate` in March 2018, however
there was no release of flask-sqlalchemy since then, so we need
to pull the dev version of the package from Github.
This commit is contained in:
Alexey Bezhan
2019-01-07 17:12:00 +00:00
parent fe498f9a79
commit 47c403f6ab
7 changed files with 42 additions and 3 deletions

View File

@@ -909,6 +909,16 @@ def test_should_return_notifications_including_one_offs_by_default(sample_user,
assert len(include_one_offs_by_default) == 2
def test_should_not_count_pages_when_given_a_flag(sample_user, sample_template):
create_notification(sample_template)
notification = create_notification(sample_template)
pagination = get_notifications_for_service(sample_template.service_id, count_pages=False, page_size=1)
assert len(pagination.items) == 1
assert pagination.total is None
assert pagination.items[0].id == notification.id
def test_get_notifications_created_by_api_or_csv_are_returned_correctly_excluding_test_key_notifications(
notify_db,
notify_db_session,

View File

@@ -1407,6 +1407,28 @@ def test_get_only_api_created_notifications_for_service(
assert resp['notifications'][0]['id'] == str(without_job.id)
def test_get_notifications_for_service_without_page_count(
admin_request,
sample_job,
sample_template,
sample_user,
):
create_notification(sample_template)
without_job = create_notification(sample_template)
resp = admin_request.get(
'service.get_all_notifications_for_service',
service_id=sample_template.service_id,
page_size=1,
include_jobs=False,
include_one_off=False,
count_pages=False
)
assert len(resp['notifications']) == 1
assert resp['total'] is None
assert resp['notifications'][0]['id'] == str(without_job.id)
@pytest.mark.parametrize('should_prefix', [
True,
False,