mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
remove all() from statement
This commit is contained in:
@@ -307,24 +307,25 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date):
|
|||||||
|
|
||||||
|
|
||||||
def fetch_notification_statuses_for_job(job_id):
|
def fetch_notification_statuses_for_job(job_id):
|
||||||
return (
|
stmt = (
|
||||||
db.session.query(
|
select(
|
||||||
FactNotificationStatus.notification_status.label("status"),
|
FactNotificationStatus.notification_status.label("status"),
|
||||||
func.sum(FactNotificationStatus.notification_count).label("count"),
|
func.sum(FactNotificationStatus.notification_count).label("count"),
|
||||||
)
|
)
|
||||||
|
.select_from(FactNotificationStatus)
|
||||||
.filter(
|
.filter(
|
||||||
FactNotificationStatus.job_id == job_id,
|
FactNotificationStatus.job_id == job_id,
|
||||||
)
|
)
|
||||||
.group_by(FactNotificationStatus.notification_status)
|
.group_by(FactNotificationStatus.notification_status)
|
||||||
.all()
|
|
||||||
)
|
)
|
||||||
|
return db.session.execute(stmt).all()
|
||||||
|
|
||||||
|
|
||||||
def fetch_stats_for_all_services_by_date_range(
|
def fetch_stats_for_all_services_by_date_range(
|
||||||
start_date, end_date, include_from_test_key=True
|
start_date, end_date, include_from_test_key=True
|
||||||
):
|
):
|
||||||
stats = (
|
stats = (
|
||||||
db.session.query(
|
select(
|
||||||
FactNotificationStatus.service_id.label("service_id"),
|
FactNotificationStatus.service_id.label("service_id"),
|
||||||
Service.name.label("name"),
|
Service.name.label("name"),
|
||||||
Service.restricted.label("restricted"),
|
Service.restricted.label("restricted"),
|
||||||
@@ -336,6 +337,7 @@ def fetch_stats_for_all_services_by_date_range(
|
|||||||
FactNotificationStatus.notification_status.cast(db.Text).label("status"),
|
FactNotificationStatus.notification_status.cast(db.Text).label("status"),
|
||||||
func.sum(FactNotificationStatus.notification_count).label("count"),
|
func.sum(FactNotificationStatus.notification_count).label("count"),
|
||||||
)
|
)
|
||||||
|
.select_from(FactNotificationStatus)
|
||||||
.filter(
|
.filter(
|
||||||
FactNotificationStatus.local_date >= start_date,
|
FactNotificationStatus.local_date >= start_date,
|
||||||
FactNotificationStatus.local_date <= end_date,
|
FactNotificationStatus.local_date <= end_date,
|
||||||
@@ -360,12 +362,13 @@ def fetch_stats_for_all_services_by_date_range(
|
|||||||
if start_date <= utc_now().date() <= end_date:
|
if start_date <= utc_now().date() <= end_date:
|
||||||
today = get_midnight_in_utc(utc_now())
|
today = get_midnight_in_utc(utc_now())
|
||||||
subquery = (
|
subquery = (
|
||||||
db.session.query(
|
select(
|
||||||
Notification.notification_type.label("notification_type"),
|
Notification.notification_type.label("notification_type"),
|
||||||
Notification.status.label("status"),
|
Notification.status.label("status"),
|
||||||
Notification.service_id.label("service_id"),
|
Notification.service_id.label("service_id"),
|
||||||
func.count(Notification.id).label("count"),
|
func.count(Notification.id).label("count"),
|
||||||
)
|
)
|
||||||
|
.select_from(Notification)
|
||||||
.filter(Notification.created_at >= today)
|
.filter(Notification.created_at >= today)
|
||||||
.group_by(
|
.group_by(
|
||||||
Notification.notification_type,
|
Notification.notification_type,
|
||||||
@@ -377,7 +380,7 @@ def fetch_stats_for_all_services_by_date_range(
|
|||||||
subquery = subquery.filter(Notification.key_type != KeyType.TEST)
|
subquery = subquery.filter(Notification.key_type != KeyType.TEST)
|
||||||
subquery = subquery.subquery()
|
subquery = subquery.subquery()
|
||||||
|
|
||||||
stats_for_today = db.session.query(
|
stats_for_today = select(
|
||||||
Service.id.label("service_id"),
|
Service.id.label("service_id"),
|
||||||
Service.name.label("name"),
|
Service.name.label("name"),
|
||||||
Service.restricted.label("restricted"),
|
Service.restricted.label("restricted"),
|
||||||
@@ -390,7 +393,7 @@ def fetch_stats_for_all_services_by_date_range(
|
|||||||
|
|
||||||
all_stats_table = stats.union_all(stats_for_today).subquery()
|
all_stats_table = stats.union_all(stats_for_today).subquery()
|
||||||
query = (
|
query = (
|
||||||
db.session.query(
|
select(
|
||||||
all_stats_table.c.service_id,
|
all_stats_table.c.service_id,
|
||||||
all_stats_table.c.name,
|
all_stats_table.c.name,
|
||||||
all_stats_table.c.restricted,
|
all_stats_table.c.restricted,
|
||||||
@@ -417,7 +420,7 @@ def fetch_stats_for_all_services_by_date_range(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
query = stats
|
query = stats
|
||||||
return query.all()
|
return db.session.execute(query).all()
|
||||||
|
|
||||||
|
|
||||||
def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user