Use MapSets for performance
Not noticeable with current database size, but lays a good foundation for larger libraries. For example, given a list of 300 artist IDs, checking if an ID is in the list takes between 30 and 40 ms (for an ID towards the end of the list), while the MapSet version takes consistently between 15 and 20 ms.
This commit is contained in:
@@ -56,7 +56,7 @@ defmodule MusicLibrary.Collection do
|
||||
where: fragment("records.purchased_at IS NOT NULL"),
|
||||
select: r.value
|
||||
|
||||
Repo.all(q)
|
||||
q |> Repo.all() |> MapSet.new()
|
||||
end
|
||||
|
||||
defp base_search do
|
||||
|
||||
@@ -103,7 +103,7 @@ defmodule MusicLibrary.Records do
|
||||
def get_all_artist_ids do
|
||||
q = from ar in ArtistRecord, distinct: true, select: ar.musicbrainz_id
|
||||
|
||||
Repo.all(q)
|
||||
q |> Repo.all() |> MapSet.new()
|
||||
end
|
||||
|
||||
def get_artist_records(musicbrainz_id) do
|
||||
|
||||
@@ -27,7 +27,7 @@ defmodule MusicLibrary.Wishlist do
|
||||
where: fragment("records.purchased_at IS NULL"),
|
||||
select: r.value
|
||||
|
||||
Repo.all(q)
|
||||
q |> Repo.all() |> MapSet.new()
|
||||
end
|
||||
|
||||
defp base_search do
|
||||
|
||||
Reference in New Issue
Block a user