@@ -3,7 +3,8 @@ defmodule MusicLibrary.Artists do
|
||||
|
||||
alias MusicLibrary.Artists.ArtistInfo
|
||||
alias MusicLibrary.Assets
|
||||
alias MusicLibrary.Records.{ArtistRecord, Record}
|
||||
alias MusicLibrary.Collection
|
||||
alias MusicLibrary.Records.ArtistRecord
|
||||
alias MusicLibrary.{Repo, Worker}
|
||||
|
||||
@spec get_artist!(String.t()) :: map()
|
||||
@@ -21,7 +22,7 @@ defmodule MusicLibrary.Artists do
|
||||
def get_similar_artists(artist) do
|
||||
case LastFm.get_similar_artists(artist.musicbrainz_id, artist.name) do
|
||||
{:ok, artists} ->
|
||||
collected_artist_ids = get_collected_artist_ids()
|
||||
collected_artist_ids = Collection.collected_artist_ids()
|
||||
|
||||
{:ok,
|
||||
Enum.filter(artists, fn a ->
|
||||
@@ -309,18 +310,6 @@ defmodule MusicLibrary.Artists do
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
defp get_collected_artist_ids do
|
||||
q =
|
||||
from ar in ArtistRecord,
|
||||
join: r in Record,
|
||||
on: r.id == ar.record_id,
|
||||
where: not is_nil(r.purchased_at),
|
||||
distinct: true,
|
||||
select: ar.musicbrainz_id
|
||||
|
||||
q |> Repo.all() |> MapSet.new()
|
||||
end
|
||||
|
||||
defp enqueue_worker(worker, params) do
|
||||
params |> worker.new(meta: %{}) |> Oban.insert()
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ defmodule MusicLibrary.Collection do
|
||||
import MusicLibrary.Records, only: [order_alphabetically: 0]
|
||||
|
||||
alias MusicLibrary.Records
|
||||
alias MusicLibrary.Records.{Record, RecordRelease, SearchIndex}
|
||||
alias MusicLibrary.Records.{ArtistRecord, Record, RecordRelease, SearchIndex}
|
||||
alias MusicLibrary.Repo
|
||||
|
||||
@excluded_genres Application.compile_env!(:music_library, :excluded_genres)
|
||||
@@ -164,6 +164,19 @@ defmodule MusicLibrary.Collection do
|
||||
select: %{record_id: rr.record_id, cover_hash: rr.cover_hash, release_id: rr.release_id}
|
||||
end
|
||||
|
||||
@spec collected_artist_ids() :: MapSet.t(String.t())
|
||||
def collected_artist_ids do
|
||||
from(ar in ArtistRecord,
|
||||
join: r in Record,
|
||||
on: r.id == ar.record_id,
|
||||
where: not is_nil(r.purchased_at),
|
||||
distinct: true,
|
||||
select: ar.musicbrainz_id
|
||||
)
|
||||
|> Repo.all()
|
||||
|> MapSet.new()
|
||||
end
|
||||
|
||||
defp base_search do
|
||||
from r in SearchIndex,
|
||||
where: not is_nil(r.purchased_at)
|
||||
|
||||
Reference in New Issue
Block a user