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:
Martyn Inglis
2017-05-23 13:40:15 +01:00
parent 39f23c6189
commit aaa0f763a1
2 changed files with 101 additions and 45 deletions

View File

@@ -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