From b8b020d0f09d72ad8bd698cea6a48dde78676168 Mon Sep 17 00:00:00 2001 From: pjurewicz Date: Thu, 7 Dec 2023 12:29:26 +0100 Subject: [PATCH] test avoiding N+1 without additional query when join used in query --- .../spec/event_repository_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 8669716b38..f3f4f17b8b 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -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)