wipe images, video, audio in /chat/1 that are 1 month old and arent reused anywhere else

master
Aevann 2024-10-24 19:46:55 +03:00
parent 655b583eb5
commit ecc45361eb
1 changed files with 5 additions and 1 deletions

View File

@ -462,13 +462,17 @@ def _cleanup_videos():
clean = [x[0] for x in db.query(MediaUsage.filename).filter_by(deleted_utc=None, removed_utc=None)]
to_delete = db.query(Media).join(Media.usages).filter(
to_delete = db.query(Media).outerjoin(Media.usages).filter(
Media.filename.notin_(clean),
Media.purged_utc == None,
Media.user_id != 380983,
or_(
MediaUsage.deleted_utc < one_month_ago,
MediaUsage.removed_utc < one_month_ago,
and_(
Media.referrer == f'{SITE_FULL}/chat/1',
Media.created_utc < one_month_ago,
),
),
).order_by(Media.size.desc())