From e4eccf4606c89dfc086a67663b63f3edb7bf30a6 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 25 Mar 2026 11:48:46 +0000 Subject: [PATCH] Move embedding regeneration to Records context Closes #131 --- lib/music_library/records.ex | 7 +++++++ lib/music_library/worker/fetch_artist_info.ex | 10 +--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index e05d033e..989bbfde 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -320,6 +320,13 @@ defmodule MusicLibrary.Records do ) end + @spec regenerate_artist_embeddings(String.t()) :: :ok + def regenerate_artist_embeddings(artist_id) do + artist_id + |> get_artist_records() + |> Enum.each(&generate_embedding_async/1) + end + @spec resize_cover(Record.t()) :: {:ok, Record.t()} | {:error, term()} def resize_cover(record) do with {:ok, thumb_data} <- Assets.Image.resize(record.cover_data), diff --git a/lib/music_library/worker/fetch_artist_info.ex b/lib/music_library/worker/fetch_artist_info.ex index 7a330d2b..c933270a 100644 --- a/lib/music_library/worker/fetch_artist_info.ex +++ b/lib/music_library/worker/fetch_artist_info.ex @@ -8,15 +8,7 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do {:ok, _artist_info} <- MusicLibrary.Artists.fetch_image(artist_id) do # fetch_lastfm_data returns {:ok, _} even on API errors, so it won't block embeddings MusicLibrary.Artists.fetch_lastfm_data(artist_id) - regenerate_record_embeddings(artist_id) + MusicLibrary.Records.regenerate_artist_embeddings(artist_id) end end - - defp regenerate_record_embeddings(artist_id) do - artist_id - |> MusicLibrary.Records.get_artist_records() - |> Enum.each(fn record -> - MusicLibrary.Records.generate_embedding_async(record) - end) - end end