From c1a4c7e508c2ca73169cf4a5997917d1080a2914 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 9 Oct 2024 14:48:07 -0700 Subject: [PATCH] convert more queries --- app/dao/services_dao.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 581a950d9..9bbaa5c75 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -514,13 +514,35 @@ def dao_fetch_stats_for_service_from_days_for_user( start_date = get_midnight_in_utc(start_date) end_date = get_midnight_in_utc(end_date + timedelta(days=1)) - return ( - db.session.query( + # return ( + # db.session.query( + # NotificationAllTimeView.notification_type, + # NotificationAllTimeView.status, + # func.date_trunc("day", NotificationAllTimeView.created_at).label("day"), + # func.count(NotificationAllTimeView.id).label("count"), + # ) + # .filter( + # NotificationAllTimeView.service_id == service_id, + # NotificationAllTimeView.key_type != KeyType.TEST, + # NotificationAllTimeView.created_at >= start_date, + # NotificationAllTimeView.created_at < end_date, + # NotificationAllTimeView.created_by_id == user_id, + # ) + # .group_by( + # NotificationAllTimeView.notification_type, + # NotificationAllTimeView.status, + # func.date_trunc("day", NotificationAllTimeView.created_at), + # ) + # .all() + # ) + stmt = ( + select( NotificationAllTimeView.notification_type, NotificationAllTimeView.status, func.date_trunc("day", NotificationAllTimeView.created_at).label("day"), func.count(NotificationAllTimeView.id).label("count"), ) + .select_from(NotificationAllTimeView) .filter( NotificationAllTimeView.service_id == service_id, NotificationAllTimeView.key_type != KeyType.TEST, @@ -533,8 +555,8 @@ def dao_fetch_stats_for_service_from_days_for_user( NotificationAllTimeView.status, func.date_trunc("day", NotificationAllTimeView.created_at), ) - .all() ) + return db.session.execute(stmt).scalars().all() def dao_fetch_todays_stats_for_all_services(