Reduce size of stats live socket
No need to store all artists IDs in the socket, instead it's enough to intersect them with the scrobbled artist IDs.
This commit is contained in:
@@ -20,12 +20,14 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
|
||||
recent_tracks = LastFm.Feed.all_tracks()
|
||||
|
||||
release_ids = release_ids(recent_tracks)
|
||||
recent_release_ids = recent_release_ids(recent_tracks)
|
||||
|
||||
collected_release_ids = Collection.collected_release_ids(release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(release_ids)
|
||||
collected_release_ids = Collection.collected_release_ids(recent_release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(recent_release_ids)
|
||||
|
||||
artist_ids = Artists.get_all_artist_ids()
|
||||
all_artist_ids = Artists.get_all_artist_ids()
|
||||
recent_artist_ids = recent_artist_ids(recent_tracks)
|
||||
artist_ids = MapSet.intersection(all_artist_ids, recent_artist_ids)
|
||||
|
||||
if connected?(socket) do
|
||||
LastFm.Feed.subscribe()
|
||||
@@ -83,12 +85,14 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
end
|
||||
|
||||
def handle_info(%{tracks: recent_tracks}, socket) do
|
||||
release_ids = release_ids(recent_tracks)
|
||||
recent_release_ids = recent_release_ids(recent_tracks)
|
||||
|
||||
collected_release_ids = Collection.collected_release_ids(release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(release_ids)
|
||||
collected_release_ids = Collection.collected_release_ids(recent_release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(recent_release_ids)
|
||||
|
||||
artist_ids = Artists.get_all_artist_ids()
|
||||
all_artist_ids = Artists.get_all_artist_ids()
|
||||
recent_artist_ids = recent_artist_ids(recent_tracks)
|
||||
artist_ids = MapSet.intersection(all_artist_ids, recent_artist_ids)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
@@ -100,13 +104,21 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
|> stream(:recent_tracks, recent_tracks, reset: true)}
|
||||
end
|
||||
|
||||
defp release_ids(recent_tracks) do
|
||||
defp recent_release_ids(recent_tracks) do
|
||||
recent_tracks
|
||||
|> Enum.map(fn t -> t.album.musicbrainz_id end)
|
||||
|> Enum.uniq()
|
||||
|> Enum.reject(fn musicbrainz_id -> musicbrainz_id == "" end)
|
||||
end
|
||||
|
||||
def recent_artist_ids(recent_tracks) do
|
||||
recent_tracks
|
||||
|> Enum.map(fn t -> t.artist.musicbrainz_id end)
|
||||
|> Enum.uniq()
|
||||
|> Enum.reject(fn musicbrainz_id -> musicbrainz_id == "" end)
|
||||
|> MapSet.new()
|
||||
end
|
||||
|
||||
# The Tailwind build step requires all needed classes to be explicitly referenced
|
||||
# in the source code, and not dynamically generated. This implies that one cannot
|
||||
# (for example) interpolate a number in a class name.
|
||||
|
||||
@@ -61,8 +61,8 @@ msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex:124
|
||||
#: lib/music_library_web/live/collection_live/index.ex:131
|
||||
#: lib/music_library_web/live/stats_live/index.ex:75
|
||||
#: lib/music_library_web/live/stats_live/index.ex:81
|
||||
#: lib/music_library_web/live/stats_live/index.ex:77
|
||||
#: lib/music_library_web/live/stats_live/index.ex:83
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:121
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:128
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -186,7 +186,7 @@ msgid "Purchased on"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex:116
|
||||
#: lib/music_library_web/live/stats_live/index.ex:67
|
||||
#: lib/music_library_web/live/stats_live/index.ex:69
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:113
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Record imported successfully"
|
||||
@@ -248,7 +248,7 @@ msgid "Something went wrong!"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/layouts/app.html.heex:8
|
||||
#: lib/music_library_web/live/stats_live/index.ex:41
|
||||
#: lib/music_library_web/live/stats_live/index.ex:43
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Stats"
|
||||
msgstr ""
|
||||
|
||||
Reference in New Issue
Block a user