From 7a4396ce6541f9d77b11611c5d4a28eaba738e23 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 24 Mar 2026 15:11:09 +0000 Subject: [PATCH] Load lastfm artist info only when bio is not present --- .../live/artist_live/show.ex | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index d6028877..648f266e 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -652,11 +652,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do |> assign(:biography, Biography.build(artist_info)) |> assign(:external_links, ArtistInfo.external_links(artist_info)) |> assign(:country, ArtistInfo.country(artist_info)) - |> assign_async(:lastfm_artist_info, fn -> - with {:ok, lastfm_artist_info} <- LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do - {:ok, %{lastfm_artist_info: lastfm_artist_info}} - end - end) + |> maybe_assign_lastfm_artist_info(artist) |> assign_async(:similar_artists, fn -> with {:ok, similar_artists} <- Artists.get_similar_artists(artist) do artist_image_hashes = Artists.get_image_hashes(similar_artists) @@ -720,6 +716,19 @@ defmodule MusicLibraryWeb.ArtistLive.Show do ) end + defp maybe_assign_lastfm_artist_info(socket, _artist) when socket.assigns.biography != nil do + socket + end + + defp maybe_assign_lastfm_artist_info(socket, artist) do + assign_async(socket, :lastfm_artist_info, fn -> + with {:ok, lastfm_artist_info} <- + LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do + {:ok, %{lastfm_artist_info: lastfm_artist_info}} + end + end) + end + defp group_and_sort(records) do {collection, wishlist} = Enum.split_with(records, fn r -> r.purchased_at end)