Drop Records embedding wrappers

This commit is contained in:
Claudio Ortolina
2026-04-11 21:29:11 +01:00
parent a608be7387
commit 3da0865725
4 changed files with 5 additions and 22 deletions
-17
View File
@@ -331,23 +331,6 @@ defmodule MusicLibrary.Records do
end end
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()} @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),
+1 -1
View File
@@ -19,7 +19,7 @@ defmodule MusicLibrary.Records.Batch do
@spec generate_embeddings() :: {:ok, [String.t()]} @spec generate_embeddings() :: {:ok, [String.t()]}
def generate_embeddings do def generate_embeddings do
Batch.run_on_all(from(r in Record), "record", fn record -> 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 end
end end
@@ -1,13 +1,15 @@
defmodule MusicLibrary.Worker.FetchArtistInfo do defmodule MusicLibrary.Worker.FetchArtistInfo do
use Oban.Worker, queue: :default, max_attempts: 3 use Oban.Worker, queue: :default, max_attempts: 3
alias MusicLibrary.Records.Similarity
@impl Oban.Worker @impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => artist_id}}) do def perform(%Oban.Job{args: %{"id" => artist_id}}) do
with {:ok, _artist_info} <- MusicLibrary.Artists.refresh_artist_info(artist_id), 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_wikipedia_data(artist_id),
{:ok, _artist_info} <- MusicLibrary.Artists.refresh_image(artist_id), {:ok, _artist_info} <- MusicLibrary.Artists.refresh_image(artist_id),
{:ok, _artist_info} <- MusicLibrary.Artists.refresh_lastfm_data(artist_id) do {: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 else
{:error, :no_english_wikipedia} -> {:cancel, :no_english_wikipedia} {:error, :no_english_wikipedia} -> {:cancel, :no_english_wikipedia}
error -> error error -> error
@@ -558,9 +558,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
case Artists.refresh_lastfm_data(musicbrainz_id) do case Artists.refresh_lastfm_data(musicbrainz_id) do
{:ok, artist_info} -> {:ok, artist_info} ->
musicbrainz_id Records.Similarity.regenerate_artist_embeddings(musicbrainz_id)
|> Records.get_artist_records()
|> Enum.each(&Records.generate_embedding_async/1)
{:noreply, {:noreply,
socket socket