@@ -3,7 +3,8 @@ defmodule MusicLibrary.Artists do
|
|||||||
|
|
||||||
alias MusicLibrary.Artists.ArtistInfo
|
alias MusicLibrary.Artists.ArtistInfo
|
||||||
alias MusicLibrary.Assets
|
alias MusicLibrary.Assets
|
||||||
alias MusicLibrary.Records.{ArtistRecord, Record}
|
alias MusicLibrary.Collection
|
||||||
|
alias MusicLibrary.Records.ArtistRecord
|
||||||
alias MusicLibrary.{Repo, Worker}
|
alias MusicLibrary.{Repo, Worker}
|
||||||
|
|
||||||
@spec get_artist!(String.t()) :: map()
|
@spec get_artist!(String.t()) :: map()
|
||||||
@@ -21,7 +22,7 @@ defmodule MusicLibrary.Artists do
|
|||||||
def get_similar_artists(artist) do
|
def get_similar_artists(artist) do
|
||||||
case LastFm.get_similar_artists(artist.musicbrainz_id, artist.name) do
|
case LastFm.get_similar_artists(artist.musicbrainz_id, artist.name) do
|
||||||
{:ok, artists} ->
|
{:ok, artists} ->
|
||||||
collected_artist_ids = get_collected_artist_ids()
|
collected_artist_ids = Collection.collected_artist_ids()
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
Enum.filter(artists, fn a ->
|
Enum.filter(artists, fn a ->
|
||||||
@@ -309,18 +310,6 @@ defmodule MusicLibrary.Artists do
|
|||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
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
|
defp enqueue_worker(worker, params) do
|
||||||
params |> worker.new(meta: %{}) |> Oban.insert()
|
params |> worker.new(meta: %{}) |> Oban.insert()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ defmodule MusicLibrary.Collection do
|
|||||||
import MusicLibrary.Records, only: [order_alphabetically: 0]
|
import MusicLibrary.Records, only: [order_alphabetically: 0]
|
||||||
|
|
||||||
alias MusicLibrary.Records
|
alias MusicLibrary.Records
|
||||||
alias MusicLibrary.Records.{Record, RecordRelease, SearchIndex}
|
alias MusicLibrary.Records.{ArtistRecord, Record, RecordRelease, SearchIndex}
|
||||||
alias MusicLibrary.Repo
|
alias MusicLibrary.Repo
|
||||||
|
|
||||||
@excluded_genres Application.compile_env!(:music_library, :excluded_genres)
|
@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}
|
select: %{record_id: rr.record_id, cover_hash: rr.cover_hash, release_id: rr.release_id}
|
||||||
end
|
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
|
defp base_search do
|
||||||
from r in SearchIndex,
|
from r in SearchIndex,
|
||||||
where: not is_nil(r.purchased_at)
|
where: not is_nil(r.purchased_at)
|
||||||
|
|||||||
@@ -156,6 +156,30 @@ defmodule MusicLibrary.CollectionTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "collected_artist_ids/0" do
|
||||||
|
setup [:fill_collection]
|
||||||
|
|
||||||
|
test "returns musicbrainz_ids for artists on collected records" do
|
||||||
|
result = Collection.collected_artist_ids()
|
||||||
|
|
||||||
|
assert is_struct(result, MapSet)
|
||||||
|
assert MapSet.size(result) > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not include artists only on wishlisted records" do
|
||||||
|
wishlisted =
|
||||||
|
record_with_artist("Wishlist Only Artist", %{
|
||||||
|
title: "Not Purchased",
|
||||||
|
purchased_at: nil
|
||||||
|
})
|
||||||
|
|
||||||
|
wishlisted_artist = hd(wishlisted.artists)
|
||||||
|
result = Collection.collected_artist_ids()
|
||||||
|
|
||||||
|
refute MapSet.member?(result, wishlisted_artist.musicbrainz_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "get_latest_record!/0" do
|
describe "get_latest_record!/0" do
|
||||||
setup [:fill_collection]
|
setup [:fill_collection]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user