diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 65d05989f..5ae34cb4e 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -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 diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index 9fedbd8ca..498e70496 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -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):