mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Added Scheduled task to get stats for template usage
Currently some pages are timing out due to the time it takes to perform database queries. This is an attempt to improve the performance by performing the query against the notification history table once a day and use the notification table for a delta between midnight and the when the page is run and combine the results. - Added Celery task for doing the work - Added a dao to handle the insert and update of the stats table - Updated tests to test the new functionality
This commit is contained in:
16
app/utils.py
16
app/utils.py
@@ -75,6 +75,22 @@ def get_london_month_from_utc_column(column):
|
||||
)
|
||||
|
||||
|
||||
def get_london_year_from_utc_column(column):
|
||||
"""
|
||||
Where queries need to count notifications by month it needs to be
|
||||
the month in BST (British Summer Time).
|
||||
The database stores all timestamps as UTC without the timezone.
|
||||
- First set the timezone on created_at to UTC
|
||||
- then convert the timezone to BST (or Europe/London)
|
||||
- lastly truncate the datetime to month with which we can group
|
||||
queries
|
||||
"""
|
||||
return func.date_trunc(
|
||||
"month",
|
||||
func.timezone("Europe/London", func.timezone("UTC", column))
|
||||
)
|
||||
|
||||
|
||||
def cache_key_for_service_template_counter(service_id, limit_days=7):
|
||||
return "{}-template-counter-limit-{}-days".format(service_id, limit_days)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user