Move sorting to db query

This commit is contained in:
Claudio Ortolina
2024-11-01 19:04:40 +00:00
parent 893890a2e9
commit 4c57f47bca
3 changed files with 5 additions and 7 deletions
@@ -7,13 +7,9 @@ defmodule MusicLibraryWeb.StatsLive.Index do
alias Records.Record
def mount(_params, _session, socket) do
collection_count_by_format =
Records.count_records_by_format()
|> Enum.sort_by(fn {_format, count} -> count end, :desc)
collection_count_by_format = Records.count_records_by_format()
collection_count_by_type =
Records.count_records_by_type()
|> Enum.sort_by(fn {_type, count} -> count end, :desc)
collection_count_by_type = Records.count_records_by_type()
collection_count =
Enum.reduce(collection_count_by_format, 0, fn {_, count}, acc -> acc + count end)