Resolve all data in one query in Scrobble Activity
Aim is to avoid having to do this in multiple rounds with in-memory operations which are harder to follow
This commit is contained in:
@@ -85,7 +85,20 @@
|
||||
class="mt-5 p-6 bg-white dark:bg-zinc-800 rounded-md shadow-sm"
|
||||
phx-update="stream"
|
||||
>
|
||||
<li :for={{id, album} <- @streams.recent_albums} id={id} class="group">
|
||||
<li
|
||||
:for={
|
||||
{id,
|
||||
%{
|
||||
album: album,
|
||||
artist_id: artist_id,
|
||||
collected_record_id: collected_record_id,
|
||||
wishlisted_record_id: wishlisted_record_id,
|
||||
cover_hash: cover_hash
|
||||
}} <- @streams.recent_albums
|
||||
}
|
||||
id={id}
|
||||
class="group"
|
||||
>
|
||||
<div class="relative pb-4 group-last:pb-0">
|
||||
<span
|
||||
class="group-last:hidden absolute left-6 top-6 -ml-px h-full w-0.5 bg-zinc-200"
|
||||
@@ -96,18 +109,18 @@
|
||||
<div class="flex min-w-0 justify-between space-x-4 items-center">
|
||||
<img
|
||||
class="h-12 w-12 rounded-md shadow-sm"
|
||||
src={album.cover_url}
|
||||
src={track_or_album_cover_url(album, cover_hash)}
|
||||
alt={album.metadata.title}
|
||||
/>
|
||||
<div>
|
||||
<p
|
||||
:if={album.artist.musicbrainz_id not in @artist_ids}
|
||||
:if={!artist_id}
|
||||
class="font-semibold text-sm block text-zinc-500 dark:text-zinc-400"
|
||||
>
|
||||
{album.artist.name}
|
||||
</p>
|
||||
<.link
|
||||
:if={album.artist.musicbrainz_id in @artist_ids}
|
||||
:if={artist_id}
|
||||
class="font-semibold text-sm block text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
|
||||
navigate={~p"/artists/#{album.artist.musicbrainz_id}"}
|
||||
>
|
||||
@@ -196,22 +209,16 @@
|
||||
{gettext("No MB ID")}
|
||||
</.badge>
|
||||
<.link
|
||||
:if={
|
||||
record_id =
|
||||
tracked_record?(@collected_releases, album.metadata.musicbrainz_id)
|
||||
}
|
||||
navigate={~p"/collection/#{record_id}"}
|
||||
:if={collected_record_id}
|
||||
navigate={~p"/collection/#{collected_record_id}"}
|
||||
>
|
||||
<.badge color="success">
|
||||
{gettext("Collected")}
|
||||
</.badge>
|
||||
</.link>
|
||||
<.link
|
||||
:if={
|
||||
record_id =
|
||||
tracked_record?(@wishlisted_releases, album.metadata.musicbrainz_id)
|
||||
}
|
||||
navigate={~p"/wishlist/#{record_id}"}
|
||||
:if={wishlisted_record_id}
|
||||
navigate={~p"/wishlist/#{wishlisted_record_id}"}
|
||||
>
|
||||
<.badge color="warning">
|
||||
{gettext("Wishlisted")}
|
||||
@@ -221,11 +228,8 @@
|
||||
|
||||
<.dropdown
|
||||
:if={
|
||||
album.metadata.musicbrainz_id !== "" and
|
||||
!tracked_record?(
|
||||
@collected_releases ++ @wishlisted_releases,
|
||||
album.metadata.musicbrainz_id
|
||||
)
|
||||
album.metadata.musicbrainz_id !== "" and !collected_record_id and
|
||||
!wishlisted_record_id
|
||||
}
|
||||
id={"actions-#{album.scrobbled_at_uts}-albums"}
|
||||
placement="bottom-end"
|
||||
@@ -266,7 +270,20 @@
|
||||
class="mt-5 p-6 bg-white dark:bg-zinc-800 rounded-md shadow-sm"
|
||||
phx-update="stream"
|
||||
>
|
||||
<li :for={{id, track} <- @streams.recent_tracks} id={id} class="group">
|
||||
<li
|
||||
:for={
|
||||
{id,
|
||||
%{
|
||||
track: track,
|
||||
artist_id: artist_id,
|
||||
collected_record_id: collected_record_id,
|
||||
wishlisted_record_id: wishlisted_record_id,
|
||||
cover_hash: cover_hash
|
||||
}} <- @streams.recent_tracks
|
||||
}
|
||||
id={id}
|
||||
class="group"
|
||||
>
|
||||
<div class="relative pb-4 group-last:pb-0">
|
||||
<span
|
||||
class="group-last:hidden absolute left-6 top-6 -ml-px h-full w-0.5 bg-zinc-200"
|
||||
@@ -277,20 +294,20 @@
|
||||
<div class="flex min-w-0 justify-between space-x-4 items-center">
|
||||
<img
|
||||
class="h-12 w-12 rounded-md shadow-sm"
|
||||
src={track.cover_url}
|
||||
src={track_or_album_cover_url(track, cover_hash)}
|
||||
alt={track.title}
|
||||
/>
|
||||
<div>
|
||||
<p
|
||||
:if={track.artist.musicbrainz_id not in @artist_ids}
|
||||
:if={!artist_id}
|
||||
class="font-semibold text-sm block text-zinc-500 dark:text-zinc-400"
|
||||
>
|
||||
{track.artist.name}
|
||||
</p>
|
||||
<.link
|
||||
:if={track.artist.musicbrainz_id in @artist_ids}
|
||||
:if={artist_id}
|
||||
class="font-semibold text-sm block text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
|
||||
navigate={~p"/artists/#{track.artist.musicbrainz_id}"}
|
||||
navigate={~p"/artists/#{artist_id}"}
|
||||
>
|
||||
{track.artist.name}
|
||||
</.link>
|
||||
@@ -407,19 +424,14 @@
|
||||
{gettext("No MB ID")}
|
||||
</.badge>
|
||||
<.link
|
||||
:if={
|
||||
record_id = tracked_record?(@collected_releases, track.album.musicbrainz_id)
|
||||
}
|
||||
navigate={~p"/collection/#{record_id}"}
|
||||
:if={collected_record_id}
|
||||
navigate={~p"/collection/#{collected_record_id}"}
|
||||
>
|
||||
<.badge color="success">{gettext("Collected")}</.badge>
|
||||
</.link>
|
||||
<.link
|
||||
:if={
|
||||
record_id =
|
||||
tracked_record?(@wishlisted_releases, track.album.musicbrainz_id)
|
||||
}
|
||||
navigate={~p"/wishlist/#{record_id}"}
|
||||
:if={wishlisted_record_id}
|
||||
navigate={~p"/wishlist/#{wishlisted_record_id}"}
|
||||
>
|
||||
<.badge color="warning">{gettext("Wishlisted")}</.badge>
|
||||
</.link>
|
||||
@@ -427,11 +439,8 @@
|
||||
|
||||
<.dropdown
|
||||
:if={
|
||||
track.album.musicbrainz_id !== "" and
|
||||
!tracked_record?(
|
||||
@collected_releases ++ @wishlisted_releases,
|
||||
track.album.musicbrainz_id
|
||||
)
|
||||
track.album.musicbrainz_id !== "" and !collected_record_id and
|
||||
!wishlisted_record_id
|
||||
}
|
||||
id={"actions-#{track.scrobbled_at_uts}-tracks"}
|
||||
placement="bottom-end"
|
||||
|
||||
Reference in New Issue
Block a user