diff --git a/Plugins/Mineplex.ReportSite/sql/6-cleanup-task.sql b/Plugins/Mineplex.ReportSite/sql/6-cleanup-task.sql index b83563c92..b0a634722 100644 --- a/Plugins/Mineplex.ReportSite/sql/6-cleanup-task.sql +++ b/Plugins/Mineplex.ReportSite/sql/6-cleanup-task.sql @@ -58,6 +58,12 @@ DO BEGIN LEFT JOIN snapshots ON reports.snapshotId = snapshots.id WHERE reportResults.closedTime NOT BETWEEN NOW() - INTERVAL 30 DAY AND NOW(); + -- DELETE SNAPSHOTS NOT LINKED TO REPORT AND OLDER THAN 30 DAYS + DELETE snapshots FROM snapshots + LEFT JOIN reports ON snapshots.id = reports.snapshotId + WHERE reports.id IS NULL + AND snapshots.created NOT BETWEEN NOW() - INTERVAL 30 DAY AND NOW(); + -- DELETE ORPHANED SNAPSHOT MESSAGES DELETE snapshotMessages FROM snapshotMessages LEFT JOIN snapshotMessageMap ON snapshotMessages.id = snapshotMessageMap.messageId