Skip to content

Commit

Permalink
Improved pruning function
Browse files Browse the repository at this point in the history
  • Loading branch information
wielas committed Dec 13, 2023
1 parent d946e2f commit 7c27cdb
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions flask_monitoringdashboard/core/database_pruning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta

from flask_monitoringdashboard.database import session_scope, Request, Outlier, CustomGraphData, CustomGraph
from flask_monitoringdashboard.database import session_scope, Request, Outlier, CustomGraphData, StackLine
from flask_monitoringdashboard.core.custom_graph import scheduler


Expand All @@ -14,16 +14,12 @@ def prune_database_older_than_weeks(weeks_to_keep, delete_custom_graph_data):

for request in requests_to_delete:
session.query(Outlier).filter(Outlier.request_id == request.id).delete()
session.query(StackLine).filter(StackLine.request_id == request.id).delete()

session.query(Request).filter(Request.time_requested < date_to_delete_from).delete()

# Prune CustomGraphData table by joining with CustomGraph to get the time_added
if delete_custom_graph_data:
old_graph_data = session.query(CustomGraphData) \
.join(CustomGraph, CustomGraph.graph_id == CustomGraphData.graph_id) \
.filter(CustomGraph.time_added < date_to_delete_from).all()
for graph_data in old_graph_data:
session.delete(graph_data)
session.query(CustomGraphData).filter(CustomGraphData.time < date_to_delete_from).delete()

session.commit()

Expand Down

0 comments on commit 7c27cdb

Please sign in to comment.