This change is a temporary fix to allow users for high volume services to use the admin app.

The trouble is the aggregate query to return the big blue numbers on the dashboard and /notifications/{notification_type} page is taking too long to return.
I have some ideas on how to improve the query, but should take some time to do some more research and test. In the meantime, let's just ignore "todays" total numbers for the high volume services. There are only two services that this will affect.
This commit is contained in:
Rebecca Law
2021-06-02 10:31:38 +01:00
parent 8b19719b48
commit b170b5ed80
2 changed files with 70 additions and 16 deletions

View File

@@ -154,23 +154,25 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
FactNotificationStatus.bst_date >= start_date,
FactNotificationStatus.key_type != KEY_TYPE_TEST
)
if str(service_id) in (current_app.config['HIGH_VOLUME_SERVICE']):
all_stats_table = stats_for_7_days.subquery()
else:
stats_for_today = db.session.query(
Notification.notification_type.cast(db.Text),
Notification.status,
*([Notification.template_id] if by_template else []),
func.count().label('count')
).filter(
Notification.created_at >= get_london_midnight_in_utc(now),
Notification.service_id == service_id,
Notification.key_type != KEY_TYPE_TEST
).group_by(
Notification.notification_type,
*([Notification.template_id] if by_template else []),
Notification.status
)
stats_for_today = db.session.query(
Notification.notification_type.cast(db.Text),
Notification.status,
*([Notification.template_id] if by_template else []),
func.count().label('count')
).filter(
Notification.created_at >= get_london_midnight_in_utc(now),
Notification.service_id == service_id,
Notification.key_type != KEY_TYPE_TEST
).group_by(
Notification.notification_type,
*([Notification.template_id] if by_template else []),
Notification.status
)
all_stats_table = stats_for_7_days.union_all(stats_for_today).subquery()
all_stats_table = stats_for_7_days.union_all(stats_for_today).subquery()
query = db.session.query(
*([