switchman 3.0.2 → 3.0.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
  SHA256:
3
- metadata.gz: 1224320ec4f3ff0d8f05d1c5537ce06f33932e4c9da069d82183aa7562e1cab4
4
- data.tar.gz: 1cd6f52c82fbdea9c3aac4c569b291428d2476abc4a2198c09beb1da64700473
3
+ metadata.gz: c3f9894955745b77bd418c8cede4882f5f37bf8cd3c0e2a3eecd53baa8658e1a
4
+ data.tar.gz: d160939ff0c15d4c57b0836abe0850e9c8a499fc05eb410932dc038d2835c60f
5
5
  SHA512:
6
- metadata.gz: 052e1675cb5d6b07844dab24c802c6f98b8e75fe4c0146a407e275d89633b5c3058801538a2537f82a7798260ad9d5dd2989536ad88d06a37bb33cf9082444dd
7
- data.tar.gz: ebaa91ea8f6be5f878ac2f8b57a7954853603cb20770f083263fd369774cedc4b33c8127a8b17746bbf4e5b91e1e742df2970be8dab08aa708baae3bc130b988
6
+ metadata.gz: 89dc3d801b5f97d2147f10bcfb691279395590b45e9631103c73f66e487345e8608e185c07f5e54429bf43d29bd3f35c017bd93cd9354a88e29d0456d1d5040f
7
+ data.tar.gz: 9893296f2801ded4b1e227a4672b0e474735d2c6ba4ff7f5e95d0591b753659a97066f422ca0615d8abbd4c1e5f9bd4c8250ff9c3c697fcb18640b3ff47dd219
@@ -87,6 +87,10 @@ module Switchman
87
87
  name.quoted
88
88
  end
89
89
 
90
+ def with_global_table_name(&block)
91
+ with_local_table_name(false, &block)
92
+ end
93
+
90
94
  def with_local_table_name(enable = true) # rubocop:disable Style/OptionalBooleanParameter
91
95
  old_value = @use_local_table_name
92
96
  @use_local_table_name = enable
@@ -15,7 +15,7 @@ module Switchman
15
15
  def convert_to_id(value)
16
16
  case value
17
17
  when ::ActiveRecord::Base
18
- value.send(primary_key)
18
+ value.id
19
19
  else
20
20
  super
21
21
  end
@@ -239,6 +239,10 @@ module Switchman
239
239
  connection.with_local_table_name { super }
240
240
  end
241
241
 
242
+ def table_name_matches?(from)
243
+ connection.with_global_table_name { super }
244
+ end
245
+
242
246
  def transpose_predicates(predicates,
243
247
  source_shard,
244
248
  target_shard,
@@ -63,7 +63,7 @@ module Switchman
63
63
  %I[update_all delete_all].each do |method|
64
64
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
65
65
  def #{method}(*args)
66
- result = self.activate { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
66
+ result = self.activate(unordered: true) { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
67
67
  result = result.sum if result.is_a?(Array)
68
68
  result
69
69
  end
@@ -103,7 +103,7 @@ module Switchman
103
103
  end
104
104
  end
105
105
 
106
- def activate(&block)
106
+ def activate(unordered: false, &block)
107
107
  shards = all_shards
108
108
  if Array === shards && shards.length == 1
109
109
  if shards.first == DefaultShard || shards.first == Shard.current(klass.connection_classes)
@@ -124,7 +124,7 @@ module Switchman
124
124
 
125
125
  shard_results = relation.activate(&block)
126
126
 
127
- if shard_results.present?
127
+ if shard_results.present? && !unordered
128
128
  can_order ||= can_order_cross_shard_results? unless order_values.empty?
129
129
  raise OrderOnMultiShardQuery if !can_order && !order_values.empty? && result_count.positive?
130
130
 
@@ -148,8 +148,12 @@ module Switchman
148
148
  results.sort! do |l, r|
149
149
  result = 0
150
150
  order_values.each do |ov|
151
- a = l.attribute(ov.expr.name)
152
- b = r.attribute(ov.expr.name)
151
+ if l.is_a?(::ActiveRecord::Base)
152
+ a = l.attribute(ov.expr.name)
153
+ b = r.attribute(ov.expr.name)
154
+ else
155
+ a, b = l, r
156
+ end
153
157
  next if a == b
154
158
 
155
159
  if a.nil? || b.nil?
@@ -150,6 +150,7 @@ module Switchman
150
150
  ::ActiveRecord::Relation.include(CallSuper)
151
151
 
152
152
  ::ActiveRecord::PredicateBuilder::AssociationQueryValue.prepend(ActiveRecord::PredicateBuilder::AssociationQueryValue)
153
+ ::ActiveRecord::PredicateBuilder::PolymorphicArrayValue.prepend(ActiveRecord::PredicateBuilder::AssociationQueryValue)
153
154
 
154
155
  ::ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend(ActiveRecord::Tasks::DatabaseTasks)
155
156
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.0.2'
4
+ VERSION = '3.0.5'
5
5
  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: 3.0.2
4
+ version: 3.0.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: 2021-06-09 00:00:00.000000000 Z
13
+ date: 2021-06-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord