From d700b581a17c60c71dbc805e6603b462e52362eb Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 17 Jan 2023 00:02:20 -0500 Subject: [PATCH] Fix filter order with annotations We were getting all artists of all time, not just for the time period --- vrobbler/apps/music/aggregators.py | 10 ++++------ vrobbler/apps/scrobbles/constants.py | 1 - vrobbler/apps/scrobbles/views.py | 12 ------------ 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/vrobbler/apps/music/aggregators.py b/vrobbler/apps/music/aggregators.py index 3833fc9..7e7d1b7 100644 --- a/vrobbler/apps/music/aggregators.py +++ b/vrobbler/apps/music/aggregators.py @@ -71,8 +71,8 @@ def top_tracks(filter: str = "today", limit: int = 15) -> List["Track"]: time_filter = Q(scrobble__timestamp__gte=STARTING_DAY_OF_CURRENT_YEAR) return ( - Track.objects.annotate(num_scrobbles=Count("scrobble", distinct=True)) - .filter(time_filter) + Track.objects.filter(time_filter) + .annotate(num_scrobbles=Count("scrobble", distinct=True)) .order_by("-num_scrobbles")[:limit] ) @@ -93,10 +93,8 @@ def top_artists(filter: str = "today", limit: int = 15) -> List["Artist"]: ) return ( - Artist.objects.annotate( - num_scrobbles=Count("track__scrobble", distinct=True) - ) - .filter(time_filter) + Artist.objects.filter(time_filter) + .annotate(num_scrobbles=Count("track__scrobble", distinct=True)) .order_by("-num_scrobbles")[:limit] ) diff --git a/vrobbler/apps/scrobbles/constants.py b/vrobbler/apps/scrobbles/constants.py index 5b90052..92e573f 100644 --- a/vrobbler/apps/scrobbles/constants.py +++ b/vrobbler/apps/scrobbles/constants.py @@ -1,3 +1,2 @@ -#!/usr/bin/env python3 JELLYFIN_VIDEO_ITEM_TYPES = ["Episode", "Movie"] JELLYFIN_AUDIO_ITEM_TYPES = ["Audio"] diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 8dcb46e..3764e53 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -39,18 +39,6 @@ from vrobbler.apps.music.aggregators import ( logger = logging.getLogger(__name__) -TRUTHY_VALUES = [ - 'true', - '1', - 't', - 'y', - 'yes', - 'yeah', - 'yup', - 'certainly', - 'uh-huh', -] - class RecentScrobbleList(ListView): model = Scrobble