From 3da0865725da25eda36d88c2ea4da5cb1b70efcb Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 11 Apr 2026 21:29:11 +0100 Subject: [PATCH] Drop Records embedding wrappers --- lib/music_library/records.ex | 17 ----------------- lib/music_library/records/batch.ex | 2 +- lib/music_library/worker/fetch_artist_info.ex | 4 +++- lib/music_library_web/live/artist_live/show.ex | 4 +--- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index c4fd26d3..f462cdf5 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -331,23 +331,6 @@ defmodule MusicLibrary.Records do end end - @spec generate_embedding_async(Record.t()) :: - {:ok, Oban.Job.t()} | {:error, Ecto.Changeset.t()} - def generate_embedding_async(record) do - enqueue_worker( - Worker.GenerateRecordEmbedding, - %{"record_id" => record.id}, - record_meta(record) - ) - 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/records/batch.ex b/lib/music_library/records/batch.ex index 4e71c939..2965c9ac 100644 --- a/lib/music_library/records/batch.ex +++ b/lib/music_library/records/batch.ex @@ -19,7 +19,7 @@ defmodule MusicLibrary.Records.Batch do @spec generate_embeddings() :: {:ok, [String.t()]} def generate_embeddings do Batch.run_on_all(from(r in Record), "record", fn record -> - Records.generate_embedding_async(record) + Records.Similarity.generate_embedding_async(record) end) end end diff --git a/lib/music_library/worker/fetch_artist_info.ex b/lib/music_library/worker/fetch_artist_info.ex index f8216869..66aa11be 100644 --- a/lib/music_library/worker/fetch_artist_info.ex +++ b/lib/music_library/worker/fetch_artist_info.ex @@ -1,13 +1,15 @@ defmodule MusicLibrary.Worker.FetchArtistInfo do use Oban.Worker, queue: :default, max_attempts: 3 + alias MusicLibrary.Records.Similarity + @impl Oban.Worker def perform(%Oban.Job{args: %{"id" => artist_id}}) do with {:ok, _artist_info} <- MusicLibrary.Artists.refresh_artist_info(artist_id), {:ok, _artist_info} <- MusicLibrary.Artists.refresh_wikipedia_data(artist_id), {:ok, _artist_info} <- MusicLibrary.Artists.refresh_image(artist_id), {:ok, _artist_info} <- MusicLibrary.Artists.refresh_lastfm_data(artist_id) do - MusicLibrary.Records.regenerate_artist_embeddings(artist_id) + Similarity.regenerate_artist_embeddings(artist_id) else {:error, :no_english_wikipedia} -> {:cancel, :no_english_wikipedia} error -> error diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 2cd25406..928c4985 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -558,9 +558,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do case Artists.refresh_lastfm_data(musicbrainz_id) do {:ok, artist_info} -> - musicbrainz_id - |> Records.get_artist_records() - |> Enum.each(&Records.generate_embedding_async/1) + Records.Similarity.regenerate_artist_embeddings(musicbrainz_id) {:noreply, socket