mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Updated delete notifications over a week old query
- PREVIOUS based on status. so as we add new status we have some orphaned rows, as these delete queries would miss them - NOW based on type. In effect they do the same thing, deleting emails, sms or letters older than a week old irrespective of status. Can see is iterating on this to have more granularity say for letters, so split up. Also means that the delete action isn't so big, as we half the affected rows, by doing it by type.
This commit is contained in:
@@ -351,11 +351,11 @@ def _filter_query(query, filter_dict=None):
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def delete_notifications_created_more_than_a_week_ago(status):
|
||||
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type):
|
||||
seven_days_ago = date.today() - timedelta(days=7)
|
||||
deleted = db.session.query(Notification).filter(
|
||||
func.date(Notification.created_at) < seven_days_ago,
|
||||
Notification.status == status,
|
||||
Notification.notification_type == notification_type,
|
||||
).delete(synchronize_session='fetch')
|
||||
db.session.commit()
|
||||
return deleted
|
||||
|
||||
Reference in New Issue
Block a user