mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Fix getting service IDs for status aggregation
Addresses [1]. Previously the query would always use UTC midnight, even after we had switched to BST (+1h). We store timestamps as naive UTC in our DB - without a timezone - but we want the query to work in terms of GMT / BST so we adjust for that - BST midnight is 11PM in UTC. [1]: https://github.com/alphagov/notifications-api/pull/3437#discussion_r791998690
This commit is contained in:
@@ -46,7 +46,11 @@ from app.models import (
|
||||
NotificationHistory,
|
||||
ProviderDetails,
|
||||
)
|
||||
from app.utils import escape_special_characters, midnight_n_days_ago
|
||||
from app.utils import (
|
||||
escape_special_characters,
|
||||
get_london_midnight_in_utc,
|
||||
midnight_n_days_ago,
|
||||
)
|
||||
|
||||
|
||||
def dao_get_last_date_template_was_used(template_id, service_id):
|
||||
@@ -797,6 +801,9 @@ def get_service_ids_with_notifications_before(notification_type, timestamp):
|
||||
|
||||
|
||||
def get_service_ids_with_notifications_on_date(notification_type, date):
|
||||
start_date = get_london_midnight_in_utc(date)
|
||||
end_date = get_london_midnight_in_utc(date + timedelta(days=1))
|
||||
|
||||
return {
|
||||
row.service_id
|
||||
for row in db.session.query(
|
||||
@@ -804,7 +811,7 @@ def get_service_ids_with_notifications_on_date(notification_type, date):
|
||||
).filter(
|
||||
Notification.notification_type == notification_type,
|
||||
# using >= + < is much more efficient than date(created_at)
|
||||
Notification.created_at >= date,
|
||||
Notification.created_at < date + timedelta(days=1)
|
||||
Notification.created_at >= start_date,
|
||||
Notification.created_at < end_date,
|
||||
).distinct()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user