Skip to content

Commit

Permalink
test avoiding N+1 without additional query when join used in query
Browse files Browse the repository at this point in the history
  • Loading branch information
pjurewicz committed Dec 7, 2023
1 parent c8c7d6f commit b8b020d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ruby_event_store-active_record/spec/event_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ module ActiveRecord
end
end

specify "avoid N+1 without additional query when join is used for querying" do
repository.append_to_stream(
[SRecord.new, SRecord.new],
Stream.new("stream"),
ExpectedVersion.auto
)
expect { repository.read(specification.stream("stream").of_type("type").result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").as_of.result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").as_at.result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").older_than(Time.now).result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").older_than_or_equal(Time.now).result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").newer_than(Time.now).result) }.to match_query_count(1)
expect { repository.read(specification.stream("stream").newer_than_or_equal(Time.now).result) }.to match_query_count(1)
end

specify "don't join events when no event filtering criteria when counting" do
expect {
repository.count(specification.stream("stream").result)
Expand Down

0 comments on commit b8b020d

Please sign in to comment.