n_plus_one_control 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f39c7dee63a881210d82f9459af15c81969f6346
4
- data.tar.gz: 1a303ce2a4b52354cf3b4036c1f925c017308097
3
+ metadata.gz: 942639e351ee999dc4a113c237d9604878d296cc
4
+ data.tar.gz: 76d9b2b2fd28b02925ce4d219e3b5c6ac316d1fb
5
5
  SHA512:
6
- metadata.gz: 4bd630b55700e20ba3cb00523d7e2b023819ffdfd802a1daae90e7532dfa86b8c4ac170378fde819b5810c694268df07d08b361c0fae84bbcbbfeff198a3e5fc
7
- data.tar.gz: 6bc7a3c38fda5837c6f8a3e0cabc3a118ef0c95bb3ffc1066fae066fe9a86a7c14ac06876704326520594b91230b5e78c1015e00f6160ee1e5e3c58953e46396
6
+ metadata.gz: 980d3feab9ebd9d9b51da847526a83ae0ed2b36e50509494d14bfad75578086b4c2ca6a6da60d5f518a6a2deb87c80af848c792046804e96b62249404f09535c
7
+ data.tar.gz: ef2d79c707712f2a578ba4ff513c1f03b6c4cf351b72381875188ac6a3730c1f73b3fd11ab7a0538f5d76f2d67a5b6fb4f57775218e1ac8b1a0877e6936bd0a9
@@ -34,6 +34,9 @@ Style/StringLiterals:
34
34
  Style/RegexpLiteral:
35
35
  Enabled: false
36
36
 
37
+ Style/Lambda:
38
+ Enabled: false
39
+
37
40
  Style/SpaceInsideStringInterpolation:
38
41
  EnforcedStyle: no_space
39
42
 
data/README.md CHANGED
@@ -167,6 +167,19 @@ NPlusOneControl.ignore = /^(BEGIN|COMMIT|SAVEPOINT|RELEASE)/
167
167
  # We track ActiveRecord event by default,
168
168
  # but can also track rom-rb events ('sql.rom') as well.
169
169
  NPlusOneControl.event = 'sql.active_record'
170
+
171
+ # configure transactional behavour for populate method
172
+ # in case of use multiple database connections
173
+ NPlusOneControl::Executor.tap do |executor|
174
+ connections = ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection)
175
+
176
+ executor.transaction_begin = -> do
177
+ connections.each { |connection| connection.begin_transaction(joinable: false) }
178
+ end
179
+ executor.transaction_rollback = -> do
180
+ connections.each(&:rollback_transaction)
181
+ end
182
+ end
170
183
  ```
171
184
 
172
185
  ## How does it work?
@@ -180,7 +193,7 @@ It may be useful to provide more matchers/assertions, for example:
180
193
  ```ruby
181
194
 
182
195
  # Actually, that means that it is N+1))
183
- assert_linear_number_of_queries { ... }
196
+ assert_linear_number_of_queries { ... }
184
197
 
185
198
  # But we can tune it with `coef` and handle such cases as selecting in batches
186
199
  assert_linear_number_of_queries(coef: 0.1) do
@@ -211,4 +224,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/palkan
211
224
  ## License
212
225
 
213
226
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
214
-
@@ -26,6 +26,9 @@ module NPlusOneControl
26
26
  end
27
27
 
28
28
  class << self
29
+ attr_accessor :transaction_begin
30
+ attr_accessor :transaction_rollback
31
+
29
32
  def call(population:, scale_factors: nil, matching: nil)
30
33
  raise ArgumentError, "Block is required!" unless block_given?
31
34
 
@@ -44,12 +47,18 @@ module NPlusOneControl
44
47
  private
45
48
 
46
49
  def with_transaction
47
- return yield unless defined?(ActiveRecord)
48
- ActiveRecord::Base.connection.begin_transaction(joinable: false)
50
+ transaction_begin.call
49
51
  yield
50
52
  ensure
51
- ActiveRecord::Base.connection.rollback_transaction
53
+ transaction_rollback.call
52
54
  end
53
55
  end
56
+
57
+ self.transaction_begin = -> do
58
+ ActiveRecord::Base.connection.begin_transaction(joinable: false)
59
+ end
60
+ self.transaction_rollback = -> do
61
+ ActiveRecord::Base.connection.rollback_transaction
62
+ end
54
63
  end
55
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NPlusOneControl
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: n_plus_one_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler