Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def create_snapshot(pads_id: str, update_blob: bytes) -> None:


async def get_latest_snapshot(pads_id: str) -> bytes | None:
row = await db.fetchone(
row: dict | None = await db.fetchone(
"""
SELECT update_blob
FROM chaospad.snapshots
Expand All @@ -124,14 +124,15 @@ async def get_latest_snapshot(pads_id: str) -> bytes | None:


async def prune_old_snapshots(pads_id: str, keep: int = 20) -> None:
limit_clause = "LIMIT -1 OFFSET :keep" if db.type == "sqlite" else "LIMIT ALL OFFSET :keep"
await db.execute(
"""
f"""
WITH old AS (
SELECT id
FROM chaospad.snapshots
WHERE pads_id = :pads_id
ORDER BY created_at DESC
LIMIT -1 OFFSET :keep
{limit_clause}
)
DELETE FROM chaospad.snapshots
WHERE id IN (SELECT id FROM old)
Expand Down
Loading