Merge branch 'federation-cache-cleaning' into 'develop'

Ensure cache_cleaning only targets remote files

See merge request funkwhale/funkwhale!424
This commit is contained in:
Eliot Berriot 2018-09-28 19:36:38 +00:00
commit 4d425e92ee
2 changed files with 13 additions and 3 deletions

View file

@ -30,7 +30,8 @@ def clean_music_cache():
candidates = (
music_models.Upload.objects.filter(
Q(audio_file__isnull=False)
& (Q(accessed_date__lt=limit) | Q(accessed_date=None))
& (Q(accessed_date__lt=limit) | Q(accessed_date=None)),
# library__actor__user=None,
)
.local(False)
.exclude(audio_file="")
@ -56,8 +57,10 @@ def get_files(storage, *parts):
"""
if not parts:
raise ValueError("Missing path")
dirs, files = storage.listdir(os.path.join(*parts))
try:
dirs, files = storage.listdir(os.path.join(*parts))
except FileNotFoundError:
return []
for dir in dirs:
files += get_files(storage, *(list(parts) + [dir]))
return [os.path.join(parts[-1], path) for path in files]