Merge branch '1011-skipped-not-prunable' into 'master'

Fix #1011: Ensure tracks linked to skipped upload can be pruned

See merge request funkwhale/funkwhale!1117
This commit is contained in:
Agate 2020-05-07 13:55:58 +02:00
commit 6486206c5a
3 changed files with 11 additions and 2 deletions

View File

@ -817,9 +817,15 @@ def get_prunable_tracks(
Returns a list of tracks with no associated uploads,
excluding the one that were listened/favorited/included in playlists.
"""
purgeable_tracks_with_upload = (
models.Upload.objects.exclude(track=None)
.filter(import_status="skipped")
.values("track")
)
queryset = models.Track.objects.all()
queryset = queryset.filter(uploads__isnull=True)
queryset = queryset.filter(
Q(uploads__isnull=True) | Q(pk__in=purgeable_tracks_with_upload)
)
if exclude_favorites:
queryset = queryset.filter(track_favorites__isnull=True)
if exclude_playlists:

View File

@ -867,6 +867,8 @@ def test_clean_transcoding_cache(preferences, now, factories):
def test_get_prunable_tracks(factories):
prunable_track = factories["music.Track"]()
# track is still prunable if it has a skipped upload linked to it
factories["music.Upload"](import_status="skipped", track=prunable_track)
# non prunable tracks
factories["music.Upload"]()
factories["favorites.TrackFavorite"]()

View File

@ -0,0 +1 @@
Ensure tracks linked to skipped upload can be pruned (#1011)