Refactor update to notifcations to be a bulk update. This is much better for performance.

This commit is contained in:
Rebecca Law
2017-04-07 10:59:12 +01:00
parent cf3eeb2120
commit 50a5bedcbf
3 changed files with 54 additions and 9 deletions

View File

@@ -439,3 +439,18 @@ def is_delivery_slow_for_provider(
(Notification.updated_at - Notification.sent_at) >= delivery_time,
).count()
return count >= threshold
@statsd(namespace="dao")
@transactional
def dao_update_notifications_sent_to_dvla(job_id, provider):
updated_count = db.session.query(Notification
).filter(Notification.job_id == job_id
).update({'status': 'sending', "sent_by": provider})
# only update NotificationHistory if api key typ is not test
db.session.query(NotificationHistory
).filter(NotificationHistory.job_id == job_id,
NotificationHistory.key_type != KEY_TYPE_TEST
).update({'status': 'sending', "sent_by": provider})
return updated_count