Files
notifications-api/app/dao/service_data_retention_dao.py
Leo Hemsted 49cc1b643f split delete task up into per service
we really don't gain anything by running each service delete in sequence
- we get the services, and then just loop through them deleting per
service. By deleting per service in separate tasks, we can take
advantage of parallelism. the only thing we lose is some log lines but I
don't think we're that interested in them.

only set query limit at the move_notifications dao function - the task
doesn't really care about the technical implementation of how it deletes
the notifications
2021-12-14 15:24:34 +00:00

57 lines
2.0 KiB
Python

from datetime import datetime
from app import db
from app.dao.dao_utils import autocommit
from app.models import ServiceDataRetention
def fetch_service_data_retention_by_id(service_id, data_retention_id):
data_retention = ServiceDataRetention.query.filter_by(service_id=service_id, id=data_retention_id).first()
return data_retention
def fetch_service_data_retention(service_id):
data_retention_list = ServiceDataRetention.query.filter_by(
service_id=service_id
).order_by(
# in the order that models.notification_types are created (email, sms, letter)
ServiceDataRetention.notification_type
).all()
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
@autocommit
def insert_service_data_retention(service_id, notification_type, days_of_retention):
new_data_retention = ServiceDataRetention(service_id=service_id,
notification_type=notification_type,
days_of_retention=days_of_retention)
db.session.add(new_data_retention)
return new_data_retention
@autocommit
def update_service_data_retention(service_data_retention_id, service_id, days_of_retention):
updated_count = ServiceDataRetention.query.filter(
ServiceDataRetention.id == service_data_retention_id,
ServiceDataRetention.service_id == service_id
).update(
{
"days_of_retention": days_of_retention,
"updated_at": datetime.utcnow()
}
)
return updated_count
def fetch_service_data_retention_for_all_services_by_notification_type(notification_type):
return ServiceDataRetention.query.filter(ServiceDataRetention.notification_type == notification_type).all()