mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 00:11:16 -05:00
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:
@@ -633,7 +633,11 @@ def dao_get_notifications_by_recipient_or_reference(service_id, search_term, not
|
||||
if 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
|
||||
|
||||
|
||||
|
||||
@@ -1057,6 +1057,24 @@ def test_dao_get_notifications_by_recipient(sample_template):
|
||||
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",
|
||||
["JACK", "JACK@gmail.com", "jack@gmail.com"])
|
||||
def test_dao_get_notifications_by_recipient_is_not_case_sensitive(sample_email_template, search_term):
|
||||
|
||||
Reference in New Issue
Block a user