mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
Purge noti to email reply to older than 7 days
This commit is contained in:
@@ -26,14 +26,15 @@ from app.dao.date_util import get_financial_year
|
||||
from app.models import (
|
||||
Service,
|
||||
Notification,
|
||||
NotificationEmailReplyTo,
|
||||
NotificationHistory,
|
||||
NotificationStatistics,
|
||||
NotificationEmailReplyTo,
|
||||
ServiceEmailReplyTo,
|
||||
ScheduledNotification,
|
||||
ServiceEmailReplyTo,
|
||||
Template,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEST,
|
||||
EMAIL_TYPE,
|
||||
LETTER_TYPE,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
@@ -376,6 +377,22 @@ def delete_notifications_created_more_than_a_week_ago_by_type(notification_type)
|
||||
return deleted
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def delete_notification_to_email_reply_to_more_than_a_week_ago():
|
||||
seven_days_ago = date.today() - timedelta(days=7)
|
||||
|
||||
subq = db.session.query(Notification.id).filter(
|
||||
func.date(Notification.created_at) < seven_days_ago
|
||||
).subquery()
|
||||
deleted = db.session.query(
|
||||
NotificationEmailReplyTo
|
||||
).filter(
|
||||
NotificationEmailReplyTo.notification_id.in_(subq)
|
||||
).delete(synchronize_session='fetch')
|
||||
db.session.commit()
|
||||
return deleted
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def dao_delete_notifications_and_history_by_id(notification_id):
|
||||
|
||||
Reference in New Issue
Block a user