Skip to content

Delete MediaLit assets when their resource is deleted #157

Closed

Description

@clbotdev

Deleting a resource never deletes its MediaLit assets, so uploaded files pile up in MediaLit and count against storage forever.

Current behaviour

  • Deleting a template, a sequence or a sequence email calls deleteMediaReferencesForResource. That removes the media_references rows, but the media row and the MediaLit file (apps/api/src/media/service.ts deleteMedia) stay behind.
  • deleteUnusedMedia only runs when a user deletes a file from the Media page.
  • deleteTeamMediaFiles (apps/api/src/media/queries.ts) exists but nothing calls it, so archiving a team (and, later, deleting an org or account) leaves all of its MediaLit files behind.

Scope

  • Add one shared helper: after a resource's references are removed, delete every media row it referenced that now has zero references, both in MediaLit and in the database. Run it for template, sequence and sequence email deletes, and for any new deletes added under Delete actions across SendLit #152.
  • Delete the team's MediaLit files when a team is purged, and when an organization or account is deleted (Delete an organization from the dashboard #151, Delete account #134). Decide whether this happens at archive time or at a later purge, because archived teams can be restored.
  • Do not break sent mail: emails already delivered and web-archive pages load images by URL. Never delete media referenced by a sent or archived broadcast or sequence email. Only purge it when that content is hard-deleted. Decide whether to keep a grace period.
  • Make MediaLit deletes retryable (queue/outbox). A MediaLit outage must not block the delete or leave the database pointing at missing files. Send failures to captureError.
  • Optional: a one-off cleanup script for media that is already orphaned.

Tests (required)

Mock the MediaLit client with mock.module() on src/media/service.ts. For every delete path, assert that deleteMedia is called with exactly the mediaLitIds the deleted entity owned, and that the media rows are gone:

  • Template delete: its media is deleted, and media still used by another template or email is not deleted.
  • Sequence email delete and sequence delete: all emails' media is deleted, and shared media is kept.
  • Broadcast delete (draft): media is deleted. A sent or archived broadcast: media is kept.
  • Team purge, org delete and account delete: every MediaLit file of the affected teams is deleted, and other teams' files are untouched.
  • Bulk paths delete the media of every entity, not just the first.
  • MediaLit failure: the delete still succeeds, the MediaLit delete is queued for retry, and captureError is called. After a successful retry, nothing is left orphaned.
  • Team isolation: a deletion never touches another team's media with the same file.

Activity

  1. moved this from Backlog to In progress in SendLit Roadmapon Oct 29, 2026
  2. added a commit that references this issue on Oct 29, 2026
  3. moved this from In progress to Done in SendLit Roadmapon Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestseverity: mediumNotable gap with a workaround, or competitive parity

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions