From 2d8989a8d0075f2b035ecb47c741f6afcff2aeb0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 25 May 2026 09:42:14 +0300 Subject: [PATCH] ML-169.8: keep latest record query synchronous get_latest_record is a single fast ORDER BY LIMIT 1 query -- no reason to async-load it. Removes the <.async_result> wrapper and the now-unnecessary render_async() from its test. --- .../live/stats_live/index.ex | 32 ++++--------------- .../live/stats_live/index_test.exs | 1 - 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index d4c1d075..efa85b80 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -25,29 +25,11 @@ defmodule MusicLibraryWeb.StatsLive.Index do <.section> <:title>{gettext("Records")}
- <.async_result :let={latest_record} assign={@latest_record}> - <:loading> -
-
-
-
-
-
- - <:failed :let={_reason}> -
- <.icon - name="hero-exclamation-triangle" - class="size-5 text-zinc-400 dark:text-zinc-500" - /> -
- - <.album_preview - record={latest_record} - title={gettext("Latest purchase")} - class="col-span-3 sm:col-span-2" - /> - + <.album_preview + record={@latest_record} + title={gettext("Latest purchase")} + class="col-span-3 sm:col-span-2" + /> <.counter title={gettext("Collection")} count={@collection_count} @@ -179,6 +161,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do |> stream(:recent_albums, []) |> assign( current_date: current_date, + latest_record: Collection.get_latest_record(), collection_count: Collection.count(), wishlist_count: Wishlist.count(), scrobble_count: ListeningStats.scrobble_count(), @@ -188,9 +171,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do current_section: :stats, rule_picker_album_title: nil ) - |> assign_async(:latest_record, fn -> - {:ok, %{latest_record: Collection.get_latest_record()}} - end) |> assign_async(:collection_summary, fn -> {:ok, %{ diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index 019515aa..e9b7e856 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -59,7 +59,6 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do session = conn |> visit("/") - |> render_async() |> assert_has("span", escape(latest_record.title)) for artist <- latest_record.artists do