Repository navigation
Delete MediaLit assets when their resource is deleted #157
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or requestseverity: mediumNotable gap with a workaround, or competitive parityNotable gap with a workaround, or competitive parity
Description
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 themedia_referencesrows, but themediarow and the MediaLit file (apps/api/src/media/service.tsdeleteMedia) stay behind. deleteUnusedMediaonly 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
mediarow 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
captureErroris called. After a successful retry, nothing is left orphaned. - Team isolation: a deletion never touches another team's media with the same file.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestseverity: mediumNotable gap with a workaround, or competitive parityNotable gap with a workaround, or competitive parity
Type
Projects
- StatusShow more project fieldsDone
Activity
Merge pull request #162 from codelitdev/feat/157-medialit-cleanup