switchman 1.9.4 → 1.9.5

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: 7953977b213e8fd57db12680f2e250db59e6cee0
4
- data.tar.gz: 86a55be8ebd4c40c7071d0ef65886fd83102a4ce
3
+ metadata.gz: 76cc38b30914de73cddc2b347abe5e0fdfd1e35f
4
+ data.tar.gz: d12887e2755b199c584906a13f51df762ed602d0
5
5
  SHA512:
6
- metadata.gz: b1ccbcf0e7281cd022bf912a7cfc4dc43dc6801c3556e942929ca4bccd9c308feaed966dc84b3321238f263356bee6b23bfa9e177450555d9786405b48e2b04a
7
- data.tar.gz: 73491652b599c6c693ffd60563aae72a63f84fef8d96c36aa7e3028edc7f0dc2099d30e328d6badc0088988b8a2b210319b8072e6874763cdb824f018e436d85
6
+ metadata.gz: 58f34befaed170ea8a74df108d28bc925edeafe994dbec25d26a93d44ec73f5b5824a8c9ba111963ee7c6d8cfa10051d434d05ff51bb1b517b87ef641f8e844b
7
+ data.tar.gz: 7ab150743f0ecc027b4935dc5e2630f2c242a53d191439789399a13433fda2d20f76f3b050f57882a3e57cb241c71659eec8ac3233423085a4b3da636214fffb
@@ -19,11 +19,11 @@ module Switchman
19
19
  @values[:shard_source]
20
20
  end
21
21
  def shard_value=(value)
22
- raise ImmutableRelation if @loaded
22
+ raise ::ActiveRecord::ImmutableRelation if @loaded
23
23
  @values[:shard] = value
24
24
  end
25
25
  def shard_source_value=(value)
26
- raise ImmutableRelation if @loaded
26
+ raise ::ActiveRecord::ImmutableRelation if @loaded
27
27
  @values[:shard_source] = value
28
28
  end
29
29
 
@@ -126,11 +126,18 @@ module Switchman
126
126
  def transpose_#{type}_clauses(source_shard, target_shard, remove_nonlocal_primary_keys)
127
127
  if ::Rails.version >= '5'
128
128
  unless (predicates = #{type}_clause.send(:predicates)).empty?
129
- new_predicates = transpose_predicates(predicates, source_shard,
130
- target_shard, remove_nonlocal_primary_keys)
131
- if new_predicates != predicates
129
+ new_predicates, new_binds = transpose_predicates(predicates, source_shard,
130
+ target_shard, remove_nonlocal_primary_keys,
131
+ binds: #{type}_clause.binds,
132
+ dup_binds_on_mutation: true)
133
+ if new_predicates != predicates || !new_binds.equal?(#{type}_clause.binds)
132
134
  self.#{type}_clause = #{type}_clause.dup
133
- #{type}_clause.instance_variable_set(:@predicates, new_predicates)
135
+ if new_predicates != predicates
136
+ #{type}_clause.instance_variable_set(:@predicates, new_predicates)
137
+ end
138
+ if !new_binds.equal?(#{type}_clause.binds)
139
+ #{type}_clause.instance_variable_set(:@binds, new_binds)
140
+ end
134
141
  end
135
142
  end
136
143
  else
@@ -181,7 +188,6 @@ module Switchman
181
188
  when ::Arel::Nodes::BindParam
182
189
  # look for a bind param with a matching column name
183
190
  if ::Rails.version >= "5"
184
- binds ||= where_clause.binds + having_clause.binds
185
191
  if binds && bind = binds.detect{|b| b&.name.to_s == klass.primary_key.to_s}
186
192
  unless bind.value.is_a?(::ActiveRecord::StatementCache::Substitute)
187
193
  local_id, id_shard = Shard.local_id_for(bind.value)
@@ -268,8 +274,13 @@ module Switchman
268
274
 
269
275
  # semi-private
270
276
  public
271
- def transpose_predicates(predicates, source_shard, target_shard, remove_nonlocal_primary_keys = false, binds = nil)
272
- predicates.map do |predicate|
277
+ def transpose_predicates(predicates,
278
+ source_shard,
279
+ target_shard,
280
+ remove_nonlocal_primary_keys = false,
281
+ binds: nil,
282
+ dup_binds_on_mutation: false)
283
+ result = predicates.map do |predicate|
273
284
  next predicate unless predicate.is_a?(::Arel::Nodes::Binary)
274
285
  next predicate unless predicate.left.is_a?(::Arel::Attributes::Attribute)
275
286
  relation, column = relation_and_column(predicate.left)
@@ -312,8 +323,13 @@ module Switchman
312
323
  when ::Arel::Nodes::BindParam
313
324
  # look for a bind param with a matching column name
314
325
  if ::Rails.version >= "5"
315
- binds ||= where_clause.binds + having_clause.binds
316
326
  if binds && bind = binds.detect{|b| b&.name.to_s == predicate.left.name.to_s}
327
+ # before we mutate, dup
328
+ if dup_binds_on_mutation
329
+ binds = binds.map(&:dup)
330
+ dup_binds_on_mutation = false
331
+ bind = binds.find { |b| b&.name.to_s == predicate.left.name.to_s }
332
+ end
317
333
  if bind.value.is_a?(::ActiveRecord::StatementCache::Substitute)
318
334
  bind.value.sharded = true # mark for transposition later
319
335
  bind.value.primary = true if type == :primary
@@ -356,6 +372,8 @@ module Switchman
356
372
  predicate.class.new(predicate.left, new_right_value)
357
373
  end
358
374
  end
375
+ result = [result, binds] if ::Rails.version >= '5'
376
+ result
359
377
  end
360
378
  end
361
379
  end
@@ -21,7 +21,7 @@ module Switchman
21
21
  where_clause = super
22
22
  predicates = where_clause.send(:predicates)
23
23
  @scope.send(:infer_shards_from_primary_key, predicates, where_clause.binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard)
24
- predicates = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, where_clause.binds)
24
+ predicates, _new_binds = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, binds: where_clause.binds)
25
25
  where_clause.instance_variable_set(:@predicates, predicates)
26
26
  where_clause
27
27
  else
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.9.4"
2
+ VERSION = "1.9.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-02 00:00:00.000000000 Z
13
+ date: 2017-03-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties