From 101498ec84a3f123f53c0ef381a499b75edd378f Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 30 Nov 2021 16:42:32 +0000 Subject: [PATCH] Improve query performance Adding a filter to `app.dao.notifications_dao.is_delivery_slow_for_providers` query to improve the performance. By added Notifications.notification_type = 'sms' to the query it will improve the performance some analyse shows 500ms improvement, which is a good thing especially when the query is run once a minute. --- app/dao/notifications_dao.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 85949dee9..0b4ba58dc 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -558,6 +558,7 @@ def is_delivery_slow_for_providers( ProviderDetails ).outerjoin( Notification, and_( + Notification.notification_type == SMS_TYPE, Notification.sent_by == ProviderDetails.identifier, Notification.created_at >= created_at, Notification.sent_at.isnot(None),