Compute artist play count from db
This commit is contained in:
@@ -26,6 +26,14 @@ defmodule MusicLibrary.ListeningStats do
|
||||
Repo.aggregate(Track, :count, :scrobbled_at_uts)
|
||||
end
|
||||
|
||||
@spec artist_play_count(String.t()) :: non_neg_integer()
|
||||
def artist_play_count(artist_musicbrainz_id) do
|
||||
from(t in Track,
|
||||
where: fragment("json_extract(?, '$.musicbrainz_id')", t.artist) == ^artist_musicbrainz_id
|
||||
)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
|
||||
@spec recent_activity(String.t(), non_neg_integer()) :: map()
|
||||
def recent_activity(timezone, limit \\ 100) do
|
||||
# When we get recent tracks, we need to:
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
import MusicLibraryWeb.RecordComponents,
|
||||
only: [record_grid: 1, country_label: 1, artist_image: 1]
|
||||
|
||||
alias MusicLibrary.{Artists, Chats, Records}
|
||||
alias MusicLibrary.{Artists, Chats, ListeningStats, Records}
|
||||
alias MusicLibrary.Artists.ArtistInfo
|
||||
alias MusicLibraryWeb.ArtistLive.Biography
|
||||
alias MusicLibraryWeb.ErrorMessages
|
||||
@@ -210,24 +210,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center justify-between">
|
||||
<.async_result :let={lastfm_artist_info} assign={@lastfm_artist_info}>
|
||||
<:loading>
|
||||
<span class="sr-only">{gettext("Loading play count")}</span>
|
||||
<.loading />
|
||||
</:loading>
|
||||
<:failed :let={_failure}>
|
||||
<div class="mt-4 text-sm/5 text-zinc-500 dark:text-zinc-400">
|
||||
<.icon
|
||||
name="hero-exclamation-triangle"
|
||||
class="-mt-1 mr-1 ml-2 size-5"
|
||||
aria-hidden="true"
|
||||
data-slot="icon"
|
||||
/>
|
||||
{gettext("Error loading play count")}
|
||||
</div>
|
||||
</:failed>
|
||||
<.play_count play_count={lastfm_artist_info.play_count} />
|
||||
</.async_result>
|
||||
<.play_count play_count={@play_count} />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -664,6 +647,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
|> assign(:current_section, :artists)
|
||||
|> assign(:artist, artist)
|
||||
|> assign(:artist_info, artist_info)
|
||||
|> assign(:play_count, ListeningStats.artist_play_count(musicbrainz_id))
|
||||
|> assign(:chat_count, Chats.count_chats(:artist, musicbrainz_id))
|
||||
|> assign(:biography, Biography.build(artist_info))
|
||||
|> assign(:external_links, ArtistInfo.external_links(artist_info))
|
||||
|
||||
@@ -299,11 +299,6 @@ msgstr ""
|
||||
msgid "Loading biography"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/artist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Loading play count"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/show.ex
|
||||
#: lib/music_library_web/live/wishlist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -333,11 +328,6 @@ msgstr ""
|
||||
msgid "Error loading biography"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/artist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Error loading play count"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex
|
||||
#: lib/music_library_web/live/record_set_live/index.ex
|
||||
#: lib/music_library_web/live/scrobble_rules_live/index.ex
|
||||
|
||||
@@ -299,11 +299,6 @@ msgstr ""
|
||||
msgid "Loading biography"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/artist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Loading play count"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/show.ex
|
||||
#: lib/music_library_web/live/wishlist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -333,11 +328,6 @@ msgstr ""
|
||||
msgid "Error loading biography"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/artist_live/show.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Error loading play count"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex
|
||||
#: lib/music_library_web/live/record_set_live/index.ex
|
||||
#: lib/music_library_web/live/scrobble_rules_live/index.ex
|
||||
|
||||
@@ -43,7 +43,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
||||
conn
|
||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||
|> unwrap(&render_async/1)
|
||||
|> assert_has("span", "123")
|
||||
|> assert_has("span", "No scrobbles")
|
||||
|> assert_has("dt", "Biography")
|
||||
end
|
||||
|
||||
@@ -64,9 +64,8 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
||||
conn
|
||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||
|> unwrap(&render_async/1)
|
||||
|> refute_has("span", "123")
|
||||
|> assert_has("span", "No scrobbles")
|
||||
|> refute_has("summary", "Biography")
|
||||
|> assert_has("div", "Error loading play count")
|
||||
|> assert_has("div", "Error loading biography")
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user