From 9f43352a64db3b0f60054d52a45ed30e79053a42 Mon Sep 17 00:00:00 2001 From: Szymon Fiedler Date: Fri, 12 Jul 2024 18:16:12 +0200 Subject: [PATCH] Deffered reader with criteria --- .../repository_reader_benchmark.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ruby_event_store-active_record/repository_reader_benchmark.rb b/ruby_event_store-active_record/repository_reader_benchmark.rb index 73e945e799..131fcb656a 100644 --- a/ruby_event_store-active_record/repository_reader_benchmark.rb +++ b/ruby_event_store-active_record/repository_reader_benchmark.rb @@ -21,7 +21,7 @@ class EventInStream < ::ActiveRecord::Base Integer(ARGV.first || 1).times do RubyEventStore::Client.new(repository: RubyEventStore::ActiveRecord::EventRepository.new(serializer: YAML)).append( - (1..1_000).map { RubyEventStore::Event.new }, + (1..1_000).map { |i| RubyEventStore::Event.new(metadata: { event_type: %w[a b c d][i % 4] }) }, ) print "." end @@ -81,9 +81,19 @@ class EventInStream < ::ActiveRecord::Base RubyEventStore::ActiveRecord::BatchEnumerator.new(spec.batch_size, spec.limit, batch_reader).each end -mk_benchmark = ->(reader) { mk_client[reader].read.each_batch { print "." } } +deffered = ->(spec, stream) do + batch_reader = ->(offset, limit) do + stream.joins( + "INNER JOIN (SELECT id FROM event_store_events WHERE event_type = 'a' LIMIT #{limit} OFFSET #{offset}) AS tmp USING(id)", + ).map(&record) + end + RubyEventStore::BatchEnumerator.new(spec.batch_size, spec.limit, batch_reader).each +end + +mk_benchmark = ->(reader) { mk_client[reader].read.of_type("a").each {} } Benchmark.bm(14) do |x| x.report("offset/limit:") { mk_benchmark[offset_limit] } x.report("id/limit:") { mk_benchmark[id_limit] } + x.report("deffered:") { mk_benchmark[deffered] } end