From 8dbabc0358a82488c454e3eec807a7d8ed5c9646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Fri, 2 Feb 2024 18:56:15 +0100 Subject: [PATCH] POC code to show savepoints from subsequent appends in transaction Related: https://github.com/RailsEventStore/rails_event_store/pull/1108 --- ruby_event_store-active_record/poc.rb | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ruby_event_store-active_record/poc.rb diff --git a/ruby_event_store-active_record/poc.rb b/ruby_event_store-active_record/poc.rb new file mode 100644 index 0000000000..cb5db8b507 --- /dev/null +++ b/ruby_event_store-active_record/poc.rb @@ -0,0 +1,47 @@ +require "bundler/inline" + +gemfile do + source "https://rubygems.org" + gem "ruby_event_store", path: ".." + gem "ruby_event_store-active_record", path: "." + gem "pg" + gem "childprocess" + gem "benchmark-ips" +end + +require "ruby_event_store" +require "ruby_event_store/active_record" + +require_relative "../support/helpers/migrator" +require_relative "../support/helpers/schema_helper" + +include SchemaHelper +establish_database_connection +drop_database +load_database_schema + +event_store = + RubyEventStore::Client.new( + repository: + RubyEventStore::ActiveRecord::EventRepository.new( + serializer: RubyEventStore::NULL + ) + ) + +mk_event = + lambda { RubyEventStore::Event.new(metadata: { event_type: "whatever" }) } + +logged_keywords = %w[COMMIT BEGIN SAVEPOINT RELEASE].freeze + +log_transaction = + lambda do |name, started, finished, unique_id, payload| + if logged_keywords.any? { |keyword| payload[:sql].start_with? keyword } + puts payload[:sql] + end + end + +ActiveSupport::Notifications.subscribed(log_transaction, /sql/) do + ActiveRecord::Base.transaction do + 100.times { event_store.append(mk_event.call) } + end +end