Limit search by recipient to 50 results

Things could get ugly if you use a short search string on a service with
lots of notifications…
This commit is contained in:
Chris Hill-Scott
2020-04-28 11:26:06 +01:00
parent 9f6bfb1b4e
commit 625aad97c9
2 changed files with 23 additions and 1 deletions

View File

@@ -633,7 +633,11 @@ def dao_get_notifications_by_recipient_or_reference(service_id, search_term, not
if notification_type: if notification_type:
filters.append(Notification.notification_type == notification_type) filters.append(Notification.notification_type == notification_type)
results = db.session.query(Notification).filter(*filters).order_by(desc(Notification.created_at)).all() results = db.session.query(Notification)\
.filter(*filters)\
.order_by(desc(Notification.created_at))\
.limit(current_app.config['PAGE_SIZE'])\
.all()
return results return results

View File

@@ -1057,6 +1057,24 @@ def test_dao_get_notifications_by_recipient(sample_template):
assert notification1.id == results[0].id assert notification1.id == results[0].id
def test_dao_get_notifications_by_recipient_is_limited_to_50_results(sample_template):
for _ in range(100):
create_notification(
template=sample_template,
to_field='+447700900855',
normalised_to='447700900855',
)
results = dao_get_notifications_by_recipient_or_reference(
sample_template.service_id,
'447700900855',
notification_type='sms'
)
assert len(results) == 50
@pytest.mark.parametrize("search_term", @pytest.mark.parametrize("search_term",
["JACK", "JACK@gmail.com", "jack@gmail.com"]) ["JACK", "JACK@gmail.com", "jack@gmail.com"])
def test_dao_get_notifications_by_recipient_is_not_case_sensitive(sample_email_template, search_term): def test_dao_get_notifications_by_recipient_is_not_case_sensitive(sample_email_template, search_term):