Skip to content

Commit 8dbabc0

Browse files
committed
POC code to show savepoints from subsequent appends in transaction
Related: #1108
1 parent 6be5f60 commit 8dbabc0

File tree

1 file changed

+47
-0
lines changed
  • ruby_event_store-active_record

1 file changed

+47
-0
lines changed

Diff for: ruby_event_store-active_record/poc.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require "bundler/inline"
2+
3+
gemfile do
4+
source "https://rubygems.org"
5+
gem "ruby_event_store", path: ".."
6+
gem "ruby_event_store-active_record", path: "."
7+
gem "pg"
8+
gem "childprocess"
9+
gem "benchmark-ips"
10+
end
11+
12+
require "ruby_event_store"
13+
require "ruby_event_store/active_record"
14+
15+
require_relative "../support/helpers/migrator"
16+
require_relative "../support/helpers/schema_helper"
17+
18+
include SchemaHelper
19+
establish_database_connection
20+
drop_database
21+
load_database_schema
22+
23+
event_store =
24+
RubyEventStore::Client.new(
25+
repository:
26+
RubyEventStore::ActiveRecord::EventRepository.new(
27+
serializer: RubyEventStore::NULL
28+
)
29+
)
30+
31+
mk_event =
32+
lambda { RubyEventStore::Event.new(metadata: { event_type: "whatever" }) }
33+
34+
logged_keywords = %w[COMMIT BEGIN SAVEPOINT RELEASE].freeze
35+
36+
log_transaction =
37+
lambda do |name, started, finished, unique_id, payload|
38+
if logged_keywords.any? { |keyword| payload[:sql].start_with? keyword }
39+
puts payload[:sql]
40+
end
41+
end
42+
43+
ActiveSupport::Notifications.subscribed(log_transaction, /sql/) do
44+
ActiveRecord::Base.transaction do
45+
100.times { event_store.append(mk_event.call) }
46+
end
47+
end

0 commit comments

Comments
 (0)