From b2e1f1f8d10d3a77415cddc4d8037961848935d8 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 23 Nov 2024 23:16:24 +0000 Subject: [PATCH] Index records by type to improve query perf --- .../20241123230827_add_type_index_to_records.exs | 7 +++++++ test/music_library/collection_test.exs | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 priv/repo/migrations/20241123230827_add_type_index_to_records.exs diff --git a/priv/repo/migrations/20241123230827_add_type_index_to_records.exs b/priv/repo/migrations/20241123230827_add_type_index_to_records.exs new file mode 100644 index 00000000..e0147b48 --- /dev/null +++ b/priv/repo/migrations/20241123230827_add_type_index_to_records.exs @@ -0,0 +1,7 @@ +defmodule MusicLibrary.Repo.Migrations.AddTypeIndexToRecords do + use Ecto.Migration + + def change do + create index("records", [:type]) + end +end diff --git a/test/music_library/collection_test.exs b/test/music_library/collection_test.exs index dbcd8925..c834add9 100644 --- a/test/music_library/collection_test.exs +++ b/test/music_library/collection_test.exs @@ -37,7 +37,7 @@ defmodule MusicLibrary.CollectionTest do setup [:fill_collection] test "returns the count of matching records, excluding wishlisted records" do - assert 2 = Collection.search_records_count("brave") + assert 2 == Collection.search_records_count("brave") end end @@ -45,7 +45,7 @@ defmodule MusicLibrary.CollectionTest do setup [:fill_collection] test "returns the count of records in the collection by format, excluding wishlisted records" do - assert [vinyl: 2, cd: 1] = Collection.count_records_by_format() + assert [vinyl: 2, cd: 1] == Collection.count_records_by_format() end end @@ -53,7 +53,7 @@ defmodule MusicLibrary.CollectionTest do setup [:fill_collection] test "returns the count of records in the collection by type, excluding wishlisted records" do - assert [live: 1, ep: 1, album: 1] = Collection.count_records_by_type() + assert [album: 1, ep: 1, live: 1] == Collection.count_records_by_type() end end