Move embedding regeneration to Records context

Closes #131
This commit is contained in:
Claudio Ortolina
2026-03-25 11:48:46 +00:00
parent abac91aa42
commit e4eccf4606
2 changed files with 8 additions and 9 deletions
+7
View File
@@ -320,6 +320,13 @@ defmodule MusicLibrary.Records do
) )
end 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()} @spec resize_cover(Record.t()) :: {:ok, Record.t()} | {:error, term()}
def resize_cover(record) do def resize_cover(record) do
with {:ok, thumb_data} <- Assets.Image.resize(record.cover_data), with {:ok, thumb_data} <- Assets.Image.resize(record.cover_data),
@@ -8,15 +8,7 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do
{:ok, _artist_info} <- MusicLibrary.Artists.fetch_image(artist_id) 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 # fetch_lastfm_data returns {:ok, _} even on API errors, so it won't block embeddings
MusicLibrary.Artists.fetch_lastfm_data(artist_id) MusicLibrary.Artists.fetch_lastfm_data(artist_id)
regenerate_record_embeddings(artist_id) MusicLibrary.Records.regenerate_artist_embeddings(artist_id)
end end
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 end