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:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user