From 7d65a7d4ab68496ea3a9f878f2b8d632606e23a1 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 1 Apr 2026 07:06:33 +0100 Subject: [PATCH] Make sure create record returns updated record --- lib/music_library/records.ex | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index 4f47fe0b..d3e5b493 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -406,18 +406,22 @@ defmodule MusicLibrary.Records do @spec create_record(map()) :: {:ok, Record.t()} | {:error, Ecto.Changeset.t()} def create_record(attrs \\ %{}) do - with {:ok, record} <- do_create_record(attrs) do - record - |> best_effort_extract_colors() - |> Record.artist_ids() - |> Enum.each(fn artist_id -> - Artists.refresh_artist_info_async(artist_id) - end) - + with {:ok, record} <- do_create_record(attrs), + record = best_effort_extract_colors(record), + :ok <- refresh_artist_info_async(record) do {:ok, record} end end + @spec refresh_artist_info_async(Record.t()) :: :ok + def refresh_artist_info_async(record) do + record + |> Record.artist_ids() + |> Enum.each(fn artist_id -> + Artists.refresh_artist_info_async(artist_id) + end) + end + defp do_create_record(attrs) do %Record{} |> Record.changeset(attrs)