Change as per code review

- fix test name
 - make query filter consistent with each other
 - add comment for clarity
 - add inner loop to continue to insert and delete notifications while the delete count is greater than 0
This commit is contained in:
Rebecca Law
2020-03-24 14:09:13 +00:00
parent f04210ba7d
commit 3ca73a35ed
2 changed files with 13 additions and 10 deletions

View File

@@ -311,9 +311,11 @@ def delete_notifications_older_than_retention_by_type(notification_type, qry_lim
day_to_delete_backwards_from = get_london_midnight_in_utc(
convert_utc_to_bst(datetime.utcnow()).date()) - timedelta(days=f.days_of_retention)
deleted += _move_notifications_to_notification_history(
notification_type, f.service_id, day_to_delete_backwards_from, qry_limit)
delete_count_per_call = 1
while delete_count_per_call > 0:
delete_count_per_call = _move_notifications_to_notification_history(
notification_type, f.service_id, day_to_delete_backwards_from, qry_limit)
deleted += delete_count_per_call
current_app.logger.info(
'Deleting {} notifications for services without flexible data retention'.format(notification_type))
@@ -350,7 +352,7 @@ def insert_notification_history_delete_notifications(
FROM notifications
WHERE service_id = :service_id
AND notification_type = :notification_type
AND created_at <= :timestamp_to_delete_backwards_from
AND created_at < :timestamp_to_delete_backwards_from
AND key_type = 'normal'
AND notification_status in ('delivered', 'permanent-failure', 'temporary-failure')
limit :qry_limit
@@ -415,6 +417,7 @@ def _move_notifications_to_notification_history(notification_type, service_id, d
qry_limit=qry_limit
)
# Deleting test Notifications, test notifications are not persisted to NotificationHistory
Notification.query.filter(
Notification.notification_type == notification_type,
Notification.service_id == service_id,