Skip to content

Commit

Permalink
fix(snapshots): Delete redundant snapshot entries
Browse files Browse the repository at this point in the history
We were accidentally creating multiple snapshot documents.
This was fixed with 37d240f63 fix(snapshots): Don't create redundant snapshot entries

This will drop the old records that are still around. And prevent it from happening again.
  • Loading branch information
adityahase committed Dec 27, 2024
1 parent 19ca3d9 commit 3e14845
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def sync_all_snapshots_from_aws():
if _should_skip_snapshot(snapshot):
continue
try:
delete_duplicate_snapshot_docs(snapshot)
if _update_snapshot_if_exists(snapshot, random_snapshot):
continue
tag_name = next(tag["Value"] for tag in snapshot["Tags"] if tag["Key"] == "Name")
Expand Down Expand Up @@ -238,6 +239,23 @@ def _should_skip_snapshot(snapshot):
return False


def delete_duplicate_snapshot_docs(snapshot):
# Delete all except one snapshot document
# It doesn't matter which one we keep
snapshot_id = snapshot["SnapshotId"]
snapshot_count = frappe.db.count("Virtual Disk Snapshot", {"snapshot_id": snapshot_id})
if snapshot_count > 1:
frappe.db.sql(
"""
DELETE

Check failure on line 250 in press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (W291)

press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py:250:11: W291 Trailing whitespace
FROM `tabVirtual Disk Snapshot`

Check failure on line 251 in press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (W291)

press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py:251:36: W291 Trailing whitespace
WHERE snapshot_id=%s

Check failure on line 252 in press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (W291)

press/press/doctype/virtual_disk_snapshot/virtual_disk_snapshot.py:252:25: W291 Trailing whitespace
LIMIT %s
""",
(snapshot_id, snapshot_count - 1),
)


def _update_snapshot_if_exists(snapshot, random_snapshot):
snapshot_id = snapshot["SnapshotId"]
if frappe.db.exists("Virtual Disk Snapshot", {"snapshot_id": snapshot_id}):
Expand Down

0 comments on commit 3e14845

Please sign in to comment.