From c7c47a029fa18c4769d70616d7ed0c64424d075f Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 10 Apr 2017 17:33:31 +0100 Subject: [PATCH] remove slow join from template-last-use query --- app/dao/notifications_dao.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 3a48eefad..614585a51 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -124,10 +124,10 @@ def dao_get_template_usage(service_id, limit_days=None): def dao_get_last_template_usage(template_id): return NotificationHistory.query.filter( NotificationHistory.template_id == template_id, - NotificationHistory.key_type != KEY_TYPE_TEST) \ - .join(Template) \ - .order_by(desc(NotificationHistory.created_at)) \ - .first() + NotificationHistory.key_type != KEY_TYPE_TEST + ).order_by( + desc(NotificationHistory.created_at) + ).first() @statsd(namespace="dao")