switchman 2.0.10 → 2.0.13
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 +4 -4
- data/lib/switchman/active_record/postgresql_adapter.rb +4 -0
- data/lib/switchman/active_record/predicate_builder.rb +1 -1
- data/lib/switchman/active_record/query_methods.rb +16 -0
- data/lib/switchman/active_record/relation.rb +6 -4
- data/lib/switchman/engine.rb +1 -0
- data/lib/switchman/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de9d4ea9f0368bf1bfe15fdb8dd6bef040a8ec107aed386eaa81f8fa444513df
|
|
4
|
+
data.tar.gz: 71b7905b40d59a4767576552c8f5d16a2b3bdaec6d910f81f18d803a9c916256
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bac07aa4f15521f123a1d95f676448d649c71eddd86fdfbbb57504f59d0c71f9ce69618aa7d1e25e93fdc278708cb2a7385d111417f23a8fc0eb1e9b6f6eefb3
|
|
7
|
+
data.tar.gz: 1c091615da88fe2f54de51de1e740336007fd13d66d0cac0b977d0e2770a6dfacd6a85bd12b689a0c610b1de5daeab4512743f0c50199e0f610806cc2f4dd629
|
|
@@ -215,6 +215,10 @@ module Switchman
|
|
|
215
215
|
name.quoted
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
+
def with_global_table_name(&block)
|
|
219
|
+
with_local_table_name(false, &block)
|
|
220
|
+
end
|
|
221
|
+
|
|
218
222
|
def with_local_table_name(enable = true)
|
|
219
223
|
old_value = @use_local_table_name
|
|
220
224
|
@use_local_table_name = enable
|
|
@@ -233,6 +233,10 @@ module Switchman
|
|
|
233
233
|
connection.with_local_table_name { super }
|
|
234
234
|
end
|
|
235
235
|
|
|
236
|
+
def table_name_matches?(from)
|
|
237
|
+
connection.with_global_table_name { super }
|
|
238
|
+
end
|
|
239
|
+
|
|
236
240
|
# semi-private
|
|
237
241
|
public
|
|
238
242
|
def transpose_predicates(predicates,
|
|
@@ -242,6 +246,18 @@ module Switchman
|
|
|
242
246
|
binds: nil,
|
|
243
247
|
dup_binds_on_mutation: false)
|
|
244
248
|
result = predicates.map do |predicate|
|
|
249
|
+
if ::Rails.version >= '5.2' && predicate.is_a?(::Arel::Nodes::And)
|
|
250
|
+
new_predicates, _binds = transpose_predicates(predicate.children, source_shard, target_shard,
|
|
251
|
+
remove_nonlocal_primary_keys,
|
|
252
|
+
binds: binds,
|
|
253
|
+
dup_binds_on_mutation: dup_binds_on_mutation)
|
|
254
|
+
next (if new_predicates == predicate.children
|
|
255
|
+
predicate
|
|
256
|
+
else
|
|
257
|
+
::Arel::Nodes::And.new(new_predicates)
|
|
258
|
+
end)
|
|
259
|
+
end
|
|
260
|
+
|
|
245
261
|
next predicate unless predicate.is_a?(::Arel::Nodes::Binary)
|
|
246
262
|
next predicate unless predicate.left.is_a?(::Arel::Attributes::Attribute)
|
|
247
263
|
relation, column = relation_and_column(predicate.left)
|
|
@@ -62,7 +62,7 @@ module Switchman
|
|
|
62
62
|
%I{update_all delete_all}.each do |method|
|
|
63
63
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
64
64
|
def #{method}(*args)
|
|
65
|
-
result = self.activate { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
|
|
65
|
+
result = self.activate(unordered: true) { |relation| relation.call_super(#{method.inspect}, Relation, *args) }
|
|
66
66
|
result = result.sum if result.is_a?(Array)
|
|
67
67
|
result
|
|
68
68
|
end
|
|
@@ -97,7 +97,7 @@ module Switchman
|
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
def activate(&block)
|
|
100
|
+
def activate(unordered: false, &block)
|
|
101
101
|
shards = all_shards
|
|
102
102
|
if (Array === shards && shards.length == 1)
|
|
103
103
|
if shards.first == DefaultShard || shards.first == Shard.current(klass.shard_category)
|
|
@@ -118,7 +118,7 @@ module Switchman
|
|
|
118
118
|
|
|
119
119
|
shard_results = relation.activate(&block)
|
|
120
120
|
|
|
121
|
-
if shard_results.present?
|
|
121
|
+
if shard_results.present? && !unordered
|
|
122
122
|
can_order ||= can_order_cross_shard_results? unless order_values.empty?
|
|
123
123
|
raise OrderOnMultiShardQuery if !can_order && !order_values.empty? && result_count.positive?
|
|
124
124
|
|
|
@@ -142,7 +142,9 @@ module Switchman
|
|
|
142
142
|
results.sort! do |l, r|
|
|
143
143
|
result = 0
|
|
144
144
|
order_values.each do |ov|
|
|
145
|
-
if l.
|
|
145
|
+
if !l.is_a?(::ActiveRecord::Base)
|
|
146
|
+
a, b = l, r
|
|
147
|
+
elsif l.respond_to?(ov.expr.name)
|
|
146
148
|
a = l.send(ov.expr.name)
|
|
147
149
|
b = r.send(ov.expr.name)
|
|
148
150
|
else
|
data/lib/switchman/engine.rb
CHANGED
|
@@ -142,6 +142,7 @@ module Switchman
|
|
|
142
142
|
|
|
143
143
|
::ActiveRecord::Relation::WhereClauseFactory.prepend(ActiveRecord::WhereClauseFactory)
|
|
144
144
|
::ActiveRecord::PredicateBuilder::AssociationQueryValue.prepend(ActiveRecord::PredicateBuilder::AssociationQueryValue)
|
|
145
|
+
::ActiveRecord::PredicateBuilder::PolymorphicArrayValue.prepend(ActiveRecord::PredicateBuilder::AssociationQueryValue)
|
|
145
146
|
::ActiveRecord::TypeCaster::Map.include(ActiveRecord::TypeCaster::Map)
|
|
146
147
|
::ActiveRecord::TypeCaster::Connection.include(ActiveRecord::TypeCaster::Connection)
|
|
147
148
|
|
data/lib/switchman/version.rb
CHANGED
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: 2.0.
|
|
4
|
+
version: 2.0.13
|
|
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-
|
|
13
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: railties
|