mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
The /platform-admin takes a long time, probably because the marshmallow schema used joins to the service table to return all the service data and is inefficient.
The query itself has not been improved much at all but by not using a marshmallow schema I hope to get the performance gain I am looking for.
This commit is contained in:
@@ -412,6 +412,35 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
|
||||
return query.all()
|
||||
|
||||
|
||||
@statsd(namespace='dao')
|
||||
def fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date, include_from_test_key=True):
|
||||
start_date = get_london_midnight_in_utc(start_date)
|
||||
end_date = get_london_midnight_in_utc(end_date + timedelta(days=1))
|
||||
table = NotificationHistory
|
||||
|
||||
if start_date >= datetime.utcnow() - timedelta(days=7):
|
||||
table = Notification
|
||||
|
||||
query = db.session.query(
|
||||
table.notification_type,
|
||||
table.status,
|
||||
func.count(table.id).label('count')
|
||||
).filter(
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date
|
||||
).group_by(
|
||||
table.notification_type,
|
||||
table.status
|
||||
).order_by(
|
||||
table.notification_type
|
||||
)
|
||||
|
||||
if not include_from_test_key:
|
||||
query = query.filter(table.key_type != KEY_TYPE_TEST)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
@transactional
|
||||
@version_class(Service)
|
||||
@version_class(ApiKey)
|
||||
|
||||
Reference in New Issue
Block a user