mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Merge branch 'master' of https://github.com/alphagov/notifications-api
This commit is contained in:
@@ -26,12 +26,13 @@ from app.dao.date_util import get_financial_year
|
||||
from app.models import (
|
||||
Service,
|
||||
Notification,
|
||||
NotificationEmailReplyTo,
|
||||
NotificationHistory,
|
||||
NotificationStatistics,
|
||||
NotificationEmailReplyTo,
|
||||
ServiceEmailReplyTo,
|
||||
ScheduledNotification,
|
||||
ServiceEmailReplyTo,
|
||||
Template,
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEST,
|
||||
LETTER_TYPE,
|
||||
@@ -366,13 +367,26 @@ def _filter_query(query, filter_dict=None):
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type):
|
||||
seven_days_ago = date.today() - timedelta(days=7)
|
||||
|
||||
# Following could be refactored when NotificationSmsReplyTo and NotificationLetterContact in models.py
|
||||
if notification_type == EMAIL_TYPE:
|
||||
subq = db.session.query(Notification.id).filter(
|
||||
func.date(Notification.created_at) < seven_days_ago,
|
||||
Notification.notification_type == notification_type
|
||||
).subquery()
|
||||
deleted = db.session.query(
|
||||
NotificationEmailReplyTo
|
||||
).filter(
|
||||
NotificationEmailReplyTo.notification_id.in_(subq)
|
||||
).delete(synchronize_session='fetch')
|
||||
|
||||
deleted = db.session.query(Notification).filter(
|
||||
func.date(Notification.created_at) < seven_days_ago,
|
||||
Notification.notification_type == notification_type,
|
||||
).delete(synchronize_session='fetch')
|
||||
db.session.commit()
|
||||
return deleted
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user