refactor: apply review comments
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
050ca4a13c
commit
ea3bdcaa65
5 changed files with 81 additions and 13 deletions
|
|
@ -219,8 +219,8 @@ defmodule MvWeb.GroupLive.ShowTest do
|
|||
end
|
||||
end
|
||||
|
||||
@moduletag :slow
|
||||
describe "performance" do
|
||||
@describetag :slow
|
||||
test "member list is loaded efficiently (no N+1 queries)", %{conn: conn} do
|
||||
group = Fixtures.group_fixture()
|
||||
|
||||
|
|
@ -236,12 +236,31 @@ defmodule MvWeb.GroupLive.ShowTest do
|
|||
)
|
||||
end)
|
||||
|
||||
# Count queries using Telemetry
|
||||
query_count_agent = Agent.start_link(fn -> 0 end) |> elem(1)
|
||||
|
||||
handler = fn _event, _measurements, _metadata, _config ->
|
||||
Agent.update(query_count_agent, &(&1 + 1))
|
||||
end
|
||||
|
||||
handler_id = "test-query-counter-#{System.unique_integer([:positive])}"
|
||||
:telemetry.attach(handler_id, [:ash, :query, :start], handler, nil)
|
||||
|
||||
{:ok, _view, html} = live(conn, "/groups/#{group.slug}")
|
||||
|
||||
final_count = Agent.get(query_count_agent, & &1)
|
||||
:telemetry.detach(handler_id)
|
||||
|
||||
# All members should be displayed
|
||||
Enum.each(members, fn member ->
|
||||
assert html =~ member.first_name or html =~ member.last_name
|
||||
end)
|
||||
|
||||
# Verify query count is reasonable (should avoid N+1 queries)
|
||||
# Expected: 1 query for group lookup + 1 query for members (with preload)
|
||||
# Allow some overhead for LiveView setup queries
|
||||
assert final_count <= 5,
|
||||
"Expected max 5 queries (group + members preload + LiveView setup), got #{final_count}. This suggests N+1 query problem."
|
||||
end
|
||||
|
||||
test "slug lookup is efficient (uses unique_slug index)", %{conn: conn} do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue