From 26c6efb59d32fbedee4a1382a0578096dc49ca23 Mon Sep 17 00:00:00 2001 From: Dan Jacob Date: Fri, 10 Jan 2025 13:25:14 +0200 Subject: [PATCH] refactor: use get() instead of first() --- radiofeed/episodes/middleware.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/radiofeed/episodes/middleware.py b/radiofeed/episodes/middleware.py index 76d2dabd1..ec3ee7866 100644 --- a/radiofeed/episodes/middleware.py +++ b/radiofeed/episodes/middleware.py @@ -1,3 +1,4 @@ +import contextlib import dataclasses from django.http import HttpRequest, HttpResponse @@ -44,12 +45,9 @@ def pop(self) -> int | None: def audio_log(self) -> AudioLog | None: """Returns audio log for the current episode in player.""" if self.request.user.is_authenticated and (episode_id := self.get()): - return ( - self.request.user.audio_logs.filter(episode_id=episode_id) - .select_related( + with contextlib.suppress(AudioLog.DoesNotExist): + return self.request.user.audio_logs.select_related( "episode", "episode__podcast", - ) - .first() - ) + ).get(episode_id=episode_id) return None