ML-169.8: reduce Stats mount sync queries to 3

Move 7 non-critical queries out of synchronous mount into assign_async
and start_async tasks with skeleton loading placeholders.

Only scalar badge counters (collection count, wishlist count, scrobble
count) remain synchronous. All async sections use <.async_result> with
loading and failed slots. Scrobble activity preserves LiveView streams
via handle_async. On-this-day date changes use AsyncResult.ok/2.
This commit is contained in:
Claudio Ortolina
2026-05-25 09:31:43 +03:00
parent 6f5c959238
commit f347f56218
6 changed files with 303 additions and 102 deletions
+7
View File
@@ -27,6 +27,13 @@ defmodule MusicLibrary.Collection do
Records.search_records_count(base_search(), query)
end
@doc "Direct scalar count for collection badge — faster than summing grouped format counts."
@spec count() :: non_neg_integer()
def count do
from(r in Record, where: not is_nil(r.purchased_at))
|> Repo.aggregate(:count)
end
@spec count_records_by_format() :: [{String.t(), non_neg_integer()}]
def count_records_by_format do
q =