From dfc12cc3540e000cc8539e9d1279b9e991f110d3 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 11 Dec 2018 14:57:10 +0000 Subject: [PATCH] Remove the join to TemplateHistory. We are adding an index to Notifications to optimize the get_notifications_for_service. We need to build the index concurrently which can not be run inside a transaction block so the index will need to be run on the db directly. CREATE INDEX CONCURRENTLY ix_notifications_service_created_at ON notifications (service_id, created_at); DROP INDEX CONCURRENTLY ix_notifications_service_created_at --- app/dao/notifications_dao.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index f5b733033..654cdf691 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -32,7 +32,6 @@ from app.models import ( NotificationHistory, ScheduledNotification, Template, - TemplateHistory, KEY_TYPE_TEST, LETTER_TYPE, NOTIFICATION_CREATED, @@ -312,7 +311,7 @@ def _filter_query(query, filter_dict=None): # filter by template template_types = multidict.getlist('template_type') if template_types: - query = query.join(TemplateHistory).filter(TemplateHistory.template_type.in_(template_types)) + query = query.filter(Notification.notification_type.in_(template_types)) return query