Delete orphan files from the image bucket nightly

OrphanFileCleanupService (03:30, ShedLock) lists the bucket and deletes objects
older than 24 hours that no images.url or users.avatar_url points to (full
URLs in legacy rows are normalised to keys), at most 5000 per run. Such files
appear when an upload via POST /api/v1/files is never attached or a request
fails between upload and save. Deleted files stay recoverable for 30 days as
noncurrent versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 01:42:39 +03:00
parent 3dcd27d08a
commit 4ff61d8eda
6 changed files with 206 additions and 0 deletions

View File

@@ -73,6 +73,14 @@ ai:
delay: 500
multiplier: 2
# Ночная чистка файлов без ссылок в бакете картинок (OrphanFileCleanupService)
storage:
orphan-cleanup:
enabled: ${STORAGE_ORPHAN_CLEANUP_ENABLED:true}
cron: "0 30 3 * * *"
min-age: PT24H # моложе — не трогаем: загрузка может ещё ждать сохранения формы
max-deletes: 5000 # предел удалений за прогон
# Обратное геокодирование (GeocodingService): публичный Nominatim требует
# User-Agent с контактом и не больше 1 запроса/с; для нагрузки — свой экземпляр
geocoding: