Skip to content

Commit

Permalink
POC code to show savepoints from subsequent appends in transaction
Browse files Browse the repository at this point in the history
Related:
#1108
  • Loading branch information
mostlyobvious committed Feb 2, 2024
1 parent 6be5f60 commit 8dbabc0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ruby_event_store-active_record/poc.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8dbabc0

Please sign in to comment.