From 789551698f5b138c5c8dd7f145c971bc0e68e7da Mon Sep 17 00:00:00 2001 From: whikernel Date: Thu, 31 Oct 2024 11:37:04 +0100 Subject: [PATCH] [FIX] Deletion of alerts with new relations --- source/app/blueprints/alerts/alerts_routes.py | 5 ++++- source/app/datamgmt/alerts/alerts_db.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/app/blueprints/alerts/alerts_routes.py b/source/app/blueprints/alerts/alerts_routes.py index db1489a31..dd83d63e2 100644 --- a/source/app/blueprints/alerts/alerts_routes.py +++ b/source/app/blueprints/alerts/alerts_routes.py @@ -28,7 +28,7 @@ from app import db from app.blueprints.case.case_comments import case_comment_update from app.datamgmt.alerts.alerts_db import get_filtered_alerts, get_alert_by_id, create_case_from_alert, \ - register_related_alerts + register_related_alerts, delete_related_alerts_cache from app.datamgmt.alerts.alerts_db import merge_alert_in_case, unmerge_alert_from_case, cache_similar_alert from app.datamgmt.alerts.alerts_db import get_related_alerts, get_related_alerts_details from app.datamgmt.alerts.alerts_db import get_alert_comments, delete_alert_comment, get_alert_comment @@ -527,6 +527,9 @@ def alerts_delete_route(alert_id) -> Response: # Delete the case association delete_similar_alert_cache(alert_id=alert_id) + # Delete the similarity entries + delete_related_alerts_cache(alert_id=alert_id) + # Delete the alert from the database db.session.delete(alert) db.session.commit() diff --git a/source/app/datamgmt/alerts/alerts_db.py b/source/app/datamgmt/alerts/alerts_db.py index b7a12ba3f..8d3745adb 100644 --- a/source/app/datamgmt/alerts/alerts_db.py +++ b/source/app/datamgmt/alerts/alerts_db.py @@ -839,6 +839,24 @@ def delete_similar_alert_cache(alert_id): db.session.commit() +def delete_related_alerts_cache(alert_id): + """ + Delete the related alerts cache + + args: + alert_id (int): The ID of the alert + + returns: + None + """ + AlertSimilarity.query.filter( + or_( + AlertSimilarity.alert_id == alert_id, + AlertSimilarity.similar_alert_id == alert_id + ) + ).delete() + db.session.commit() + def delete_similar_alerts_cache(alert_ids: List[int]): """ Delete the similar alerts cache