mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
Revert "Purge notifications for configured days of retention"
This commit is contained in:
@@ -7,6 +7,7 @@ from datetime import (
|
||||
)
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from notifications_utils.recipients import (
|
||||
validate_and_format_email_address,
|
||||
InvalidEmailError,
|
||||
@@ -41,8 +42,7 @@ from app.models import (
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENT,
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE,
|
||||
ServiceDataRetention
|
||||
EMAIL_TYPE
|
||||
)
|
||||
|
||||
from app.dao.dao_utils import transactional
|
||||
@@ -310,26 +310,10 @@ def _filter_query(query, filter_dict=None):
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type):
|
||||
flexible_data_retention = ServiceDataRetention.query.filter(
|
||||
ServiceDataRetention.notification_type == notification_type
|
||||
).all()
|
||||
|
||||
deleted = 0
|
||||
for f in flexible_data_retention:
|
||||
days_of_retention = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=f.days_of_retention)
|
||||
deleted += db.session.query(Notification).filter(
|
||||
func.date(Notification.created_at) < days_of_retention,
|
||||
Notification.notification_type == f.notification_type,
|
||||
Notification.service_id == f.service_id
|
||||
).delete(synchronize_session='fetch')
|
||||
|
||||
seven_days_ago = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=7)
|
||||
services_with_data_retention = [x.service_id for x in flexible_data_retention]
|
||||
|
||||
deleted += db.session.query(Notification).filter(
|
||||
deleted = db.session.query(Notification).filter(
|
||||
func.date(Notification.created_at) < seven_days_ago,
|
||||
Notification.notification_type == notification_type,
|
||||
Notification.service_id.notin_(services_with_data_retention)
|
||||
).delete(synchronize_session='fetch')
|
||||
return deleted
|
||||
|
||||
|
||||
@@ -20,14 +20,6 @@ def fetch_service_data_retention(service_id):
|
||||
return data_retention_list
|
||||
|
||||
|
||||
def fetch_service_data_retention_by_notification_type(service_id, notification_type):
|
||||
data_retention_list = ServiceDataRetention.query.filter_by(
|
||||
service_id=service_id,
|
||||
notification_type=notification_type
|
||||
).first()
|
||||
return data_retention_list
|
||||
|
||||
|
||||
@transactional
|
||||
def insert_service_data_retention(service_id, notification_type, days_of_retention):
|
||||
new_data_retention = ServiceDataRetention(service_id=service_id,
|
||||
|
||||
@@ -246,8 +246,9 @@ def delete_service_and_all_associated_db_objects(service):
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_fetch_stats_for_service(service_id, limit_days):
|
||||
start_date = midnight_n_days_ago(limit_days)
|
||||
def dao_fetch_stats_for_service(service_id):
|
||||
# We always want between seven and eight days
|
||||
start_date = midnight_n_days_ago(7)
|
||||
return _stats_for_service_query(service_id).filter(
|
||||
Notification.created_at >= start_date
|
||||
).all()
|
||||
|
||||
Reference in New Issue
Block a user