Update the last template usage query to check Notification table:

* Don't check the NotificationHistory table (this can cause a timeout)
* Check template actually exists first
This commit is contained in:
Imdad Ahad
2017-07-26 12:09:13 +01:00
parent 84a32180b3
commit f5e38a896c
3 changed files with 38 additions and 12 deletions

View File

@@ -149,11 +149,11 @@ def dao_get_template_usage(service_id, limit_days=None):
@statsd(namespace="dao")
def dao_get_last_template_usage(template_id):
return NotificationHistory.query.filter(
NotificationHistory.template_id == template_id,
NotificationHistory.key_type != KEY_TYPE_TEST
return Notification.query.filter(
Notification.template_id == template_id,
Notification.key_type != KEY_TYPE_TEST
).order_by(
desc(NotificationHistory.created_at)
desc(Notification.created_at)
).first()