mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 05:03:13 -04:00
convert more queries
This commit is contained in:
@@ -514,13 +514,35 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
|||||||
start_date = get_midnight_in_utc(start_date)
|
start_date = get_midnight_in_utc(start_date)
|
||||||
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
||||||
|
|
||||||
return (
|
# return (
|
||||||
db.session.query(
|
# 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.notification_type,
|
||||||
NotificationAllTimeView.status,
|
NotificationAllTimeView.status,
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||||
func.count(NotificationAllTimeView.id).label("count"),
|
func.count(NotificationAllTimeView.id).label("count"),
|
||||||
)
|
)
|
||||||
|
.select_from(NotificationAllTimeView)
|
||||||
.filter(
|
.filter(
|
||||||
NotificationAllTimeView.service_id == service_id,
|
NotificationAllTimeView.service_id == service_id,
|
||||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||||
@@ -533,8 +555,8 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
|||||||
NotificationAllTimeView.status,
|
NotificationAllTimeView.status,
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at),
|
func.date_trunc("day", NotificationAllTimeView.created_at),
|
||||||
)
|
)
|
||||||
.all()
|
|
||||||
)
|
)
|
||||||
|
return db.session.execute(stmt).scalars().all()
|
||||||
|
|
||||||
|
|
||||||
def dao_fetch_todays_stats_for_all_services(
|
def dao_fetch_todays_stats_for_all_services(
|
||||||
|
|||||||
Reference in New Issue
Block a user