Skip to content

Commit

Permalink
refactor: use get() instead of first()
Browse files Browse the repository at this point in the history
  • Loading branch information
danjac committed Jan 10, 2025
1 parent e170edc commit 26c6efb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions radiofeed/episodes/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import dataclasses

from django.http import HttpRequest, HttpResponse
Expand Down Expand Up @@ -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

0 comments on commit 26c6efb

Please sign in to comment.