v0.5.1: automatic Trash purge (cron-less background thread)

Trashed artifacts past a ~3-day retention window are now purged automatically.

- storage.purge_expired_trash(): removes trash older than TRASH_RETENTION
  (all users), tolerant of already-gone rows (concurrent-safe).
- spawn_trash_purge(): runs it on a daemon thread (manages/closes its own DB
  connection), triggered by each delete so it's cron-less and off the request
  thread. Inline fallback when AGENTFEED_ASYNC_PURGE is off (tests).
- Wired into both delete paths (API + session). Manual Empty Trash unchanged.
- Tests: purge removes expired-only; delete triggers the purge. 152 passing;
  live delete verified with the thread enabled (204, server healthy).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
peter 2026-09-07 13:01:12 +01:00
parent 4254164bef
commit 57ad58ff2d
8 changed files with 87 additions and 4 deletions

View file

@ -45,6 +45,7 @@ from .storage import (
disk_free_bytes,
make_room_for,
purge_trashed,
spawn_trash_purge,
sweep_orphan_assets,
total_allocated_bytes,
user_quota_bytes,
@ -305,6 +306,7 @@ class ArtifactDetailView(APIView):
if artifact.deleted_at is None:
artifact.deleted_at = timezone.now()
artifact.save(update_fields=["deleted_at"])
spawn_trash_purge() # sweep expired trash off the request thread
return Response(status=204)
@ -669,6 +671,7 @@ def delete_artifact(request, artifact_id):
if artifact.deleted_at is None:
artifact.deleted_at = timezone.now()
artifact.save(update_fields=["deleted_at"])
spawn_trash_purge() # sweep expired trash off the request thread
return JsonResponse({"id": artifact.id, "deleted": True})