Return count of notifications in the database for a job

When we cancel a job, we need to check if all notifications are
already in the database. So far, we were querying for all
notification objects in the database and counting them in
admin app, which runs into pagination problems for large jobs,
and could time out for very large jobs.
This commit is contained in:
Pea Tyczynska
2019-09-24 16:52:18 +01:00
parent a10aaddbcc
commit 8cf8d24e37
4 changed files with 44 additions and 1 deletions

View File

@@ -178,6 +178,11 @@ def get_notifications_for_job(service_id, job_id, filter_dict=None, page=1, page
)
@statsd(namespace="dao")
def dao_get_notification_count_for_job_id(job_id):
return Notification.query.filter_by(job_id=job_id).count()
@statsd(namespace="dao")
def get_notification_with_personalisation(service_id, notification_id, key_type):
filter_dict = {'service_id': service_id, 'id': notification_id}