Compute artist play count from db

This commit is contained in:
Claudio Ortolina
2026-03-24 15:07:50 +00:00
parent d5be6e6182
commit c9283d7f28
5 changed files with 13 additions and 42 deletions
+8
View File
@@ -26,6 +26,14 @@ defmodule MusicLibrary.ListeningStats do
Repo.aggregate(Track, :count, :scrobbled_at_uts)
end
@spec artist_play_count(String.t()) :: non_neg_integer()
def artist_play_count(artist_musicbrainz_id) do
from(t in Track,
where: fragment("json_extract(?, '$.musicbrainz_id')", t.artist) == ^artist_musicbrainz_id
)
|> Repo.aggregate(:count)
end
@spec recent_activity(String.t(), non_neg_integer()) :: map()
def recent_activity(timezone, limit \\ 100) do
# When we get recent tracks, we need to: