fibered_mysql2 0.4.0.pre.tstarck.2 → 0.4.0.pre.tstarck.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5804c1cde27f4f2a0d3c222c5f49a207930c140ebc911e71b0b4655925b83917
4
- data.tar.gz: dd33b3c3dfba5b858fc2b85832b2d65650661e53513311f9b99a62089dade8c4
3
+ metadata.gz: 0fcddd19ebaa9bb4c2bcfba7bcb7862b9fb07a31ef4ecd122d46c345a563f8ec
4
+ data.tar.gz: 65666da2f04f234f15e8945f8b693341599c478a471756963091c19c6391f770
5
5
  SHA512:
6
- metadata.gz: 72b39a4bb7c035e1ab5d7ea7929f51c08d7fd0f7cac223d97444c3352e7bcd0f078d7146a5e2a0f446c1bae69774b0e5246dd77d425a83530e92be02f4215579
7
- data.tar.gz: e4ef21a8acd88205f612d0fe23924527d4ed65f78d54ec5a397317c27ab8a1454f17b9979b830a5ffe90ab2478851114305af3706c958f3cbd559ece21adeeb5
6
+ metadata.gz: fdcc099c7c98ec0860a198d7ede37859c1c060c791f2fa33acb8659b02fabdc64f675fcbdc3cb4b555a3f40a3466945b15ebe586a14311ff70eb443e92ad30be
7
+ data.tar.gz: 755c58904cdd0405c464ba49f662b00c1747a30c61672472a683d17a8c6432e20d3c8c695ca82f34d2d4797c66741d7381ead66084478d634a04f187112c1b02
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fibered_mysql2 (0.4.0.pre.tstarck.2)
4
+ fibered_mysql2 (0.4.0.pre.tstarck.3)
5
5
  em-synchrony (~> 1.0)
6
6
  rails (>= 7.0, < 7.2)
7
7
 
@@ -54,6 +54,98 @@ module FiberedMysql2
54
54
  end
55
55
  end
56
56
 
57
+ def reset_transaction #:nodoc:
58
+ @transaction_manager = ::FiberedMysql2::FiberedMysql2Adapter_7_0::TransactionManager.new(self)
59
+ end
60
+
61
+ class TransactionManager < ::ActiveRecord::ConnectionAdapters::TransactionManager
62
+ def initialize(...)
63
+ super
64
+ @stack = Hash.new { |h, k| h[k] = [] }
65
+ end
66
+
67
+ def current_transaction #:nodoc:
68
+ _current_stack.last || ::ActiveRecord::ConnectionAdapters::TransactionManager::NULL_TRANSACTION
69
+ end
70
+
71
+ def open_transactions
72
+ _current_stack.size
73
+ end
74
+
75
+ def begin_transaction(isolation: nil, joinable: true, _lazy: true)
76
+ @connection.lock.synchronize do
77
+ run_commit_callbacks = !current_transaction.joinable?
78
+ transaction =
79
+ if _current_stack.empty?
80
+ ::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
81
+ else
82
+ ::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
83
+ end
84
+
85
+ if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
86
+ @has_unmaterialized_transactions = true
87
+ else
88
+ transaction.materialize!
89
+ end
90
+ _current_stack.push(transaction)
91
+ transaction
92
+ end
93
+ end
94
+
95
+ # Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
96
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
97
+ # transactions.
98
+ def materialize_transactions
99
+ return if @materializing_transactions
100
+ return unless @has_unmaterialized_transactions
101
+
102
+ @connection.lock.synchronize do
103
+ begin
104
+ @materializing_transactions = true
105
+ _current_stack.each { |t| t.materialize! unless t.materialized? }
106
+ ensure
107
+ @materializing_transactions = false
108
+ end
109
+ @has_unmaterialized_transactions = false
110
+ end
111
+ end
112
+
113
+ # Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
114
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
115
+ # transactions.
116
+ def commit_transaction
117
+ @connection.lock.synchronize do
118
+ transaction = _current_stack.last
119
+
120
+ begin
121
+ transaction.before_commit_records
122
+ ensure
123
+ _current_stack.pop
124
+ end
125
+
126
+ transaction.commit
127
+ transaction.commit_records
128
+ end
129
+ end
130
+
131
+ # Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
132
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
133
+ # transactions.
134
+ def rollback_transaction(transaction = nil)
135
+ @connection.lock.synchronize do
136
+ transaction ||= _current_stack.pop
137
+ transaction.rollback
138
+ transaction.rollback_records
139
+ end
140
+ end
141
+
142
+ private
143
+
144
+ def _current_stack
145
+ @stack[Fiber.current.object_id]
146
+ end
147
+ end
148
+
57
149
  private
58
150
 
59
151
  def owner_fiber
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.4.0.pre.tstarck.2"
4
+ VERSION = "0.4.0.pre.tstarck.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fibered_mysql2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre.tstarck.2
4
+ version: 0.4.0.pre.tstarck.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development