Commit 8c5924d6 authored by Eliot Berriot's avatar Eliot Berriot 💬

Ensure distinct is applied on all playable_by querysets

parent 439d4fd6
......@@ -135,9 +135,9 @@ class ArtistQuerySet(models.QuerySet):
def playable_by(self, actor, include=True):
tracks = Track.objects.playable_by(actor, include)
if include:
return self.filter(tracks__in=tracks)
return self.filter(tracks__in=tracks).distinct()
else:
return self.exclude(tracks__in=tracks)
return self.exclude(tracks__in=tracks).distinct()
class Artist(APIModelMixin):
......@@ -203,9 +203,9 @@ class AlbumQuerySet(models.QuerySet):
def playable_by(self, actor, include=True):
tracks = Track.objects.playable_by(actor, include)
if include:
return self.filter(tracks__in=tracks)
return self.filter(tracks__in=tracks).distinct()
else:
return self.exclude(tracks__in=tracks)
return self.exclude(tracks__in=tracks).distinct()
class Album(APIModelMixin):
......@@ -399,9 +399,9 @@ class TrackQuerySet(models.QuerySet):
def playable_by(self, actor, include=True):
files = Upload.objects.playable_by(actor, include)
if include:
return self.filter(uploads__in=files)
return self.filter(uploads__in=files).distinct()
else:
return self.exclude(uploads__in=files)
return self.exclude(uploads__in=files).distinct()
def annotate_duration(self):
first_upload = Upload.objects.filter(track=models.OuterRef("pk")).order_by("pk")
......@@ -557,8 +557,8 @@ class UploadQuerySet(models.QuerySet):
libraries = Library.objects.viewable_by(actor)
if include:
return self.filter(library__in=libraries, import_status="finished")
return self.exclude(library__in=libraries, import_status="finished")
return self.filter(library__in=libraries, import_status="finished").distinct()
return self.exclude(library__in=libraries, import_status="finished").distinct()
def local(self, include=True):
return self.exclude(library__actor__user__isnull=include)
......
......@@ -51,9 +51,9 @@ class PlaylistQuerySet(models.QuerySet):
def playable_by(self, actor, include=True):
plts = PlaylistTrack.objects.playable_by(actor, include)
if include:
return self.filter(playlist_tracks__in=plts)
return self.filter(playlist_tracks__in=plts).distinct()
else:
return self.exclude(playlist_tracks__in=plts)
return self.exclude(playlist_tracks__in=plts).distinct()
class Playlist(models.Model):
......@@ -167,9 +167,9 @@ class PlaylistTrackQuerySet(models.QuerySet):
def playable_by(self, actor, include=True):
tracks = music_models.Track.objects.playable_by(actor, include)
if include:
return self.filter(track__pk__in=tracks)
return self.filter(track__pk__in=tracks).distinct()
else:
return self.exclude(track__pk__in=tracks)
return self.exclude(track__pk__in=tracks).distinct()
class PlaylistTrack(models.Model):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment