mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 01:49:17 +02:00
See #272: clean transcoding files task
This commit is contained in:
parent
2fe1e7c950
commit
8489c79c89
5 changed files with 68 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
import collections
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -10,7 +11,7 @@ from django.dispatch import receiver
|
|||
from musicbrainzngs import ResponseError
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from funkwhale_api.common import channels
|
||||
from funkwhale_api.common import channels, preferences
|
||||
from funkwhale_api.federation import routes
|
||||
from funkwhale_api.federation import library as lb
|
||||
from funkwhale_api.taskapp import celery
|
||||
|
@ -526,3 +527,19 @@ def broadcast_import_status_update_to_owner(old_status, new_status, upload, **kw
|
|||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@celery.app.task(name="music.clean_transcoding_cache")
|
||||
def clean_transcoding_cache():
|
||||
delay = preferences.get("music__transcoding_cache_duration")
|
||||
if delay < 1:
|
||||
return # cache clearing disabled
|
||||
limit = timezone.now() - datetime.timedelta(minutes=delay)
|
||||
candidates = (
|
||||
models.UploadVersion.objects.filter(
|
||||
(Q(accessed_date__lt=limit) | Q(accessed_date=None))
|
||||
)
|
||||
.only("audio_file", "id")
|
||||
.order_by("id")
|
||||
)
|
||||
return candidates.delete()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue