Remove media when corresponding post(s) is deleted
It seems media isn't deleted when a post expires. A quick check tells me the same is true for posts deleted through the web interface.
When a post is deleted, I expect the media to be deleted as well (unless it's shared with another post ofc).
This may or may not be implemented together with !3677
Other info I found myself I can add here:
We store info on media in the objects table
select * from public.objects o
where o.data ->> 'type' in ('Document')
order by inserted_at
I have a bot that posts music files every hour, so I want to clean that up a bit. Posts expire after 7 days, but media remains. I look for "Document" objects that don't have a corresponding post any more with the following query. Maybe this can be a start for a better feature.
select
'rm ' || regexp_replace(replace(attachment.value ->> 'href', 'https://ilja.space/media/', ''), '/.*','') || '/*' "command"
from public.objects o
, jsonb_array_elements(o.data -> 'url') attachment
where o.data ->> 'type' in ('Document')
and o.data ->> 'actor' = 'https://ilja.space/users/cc_music_bot'
and attachment.value ->> 'href' not in (
select url ->> 'href' url from public.activities a
join public.objects o on o."data" ->> 'id' = a.data ->> 'object',
jsonb_array_elements(o.data -> 'attachment') attachment,
jsonb_array_elements(attachment -> 'url') url
where a.data ->> 'actor' = 'https://ilja.space/users/cc_music_bot'
and o.data ->> 'type' = 'Note'
)
order by inserted_at