switchman 3.6.5 → 3.6.6
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/base.rb +51 -5
- 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: 8c9938f088ef1bcce6ba0647f9e46db87d777a8b654a832bc82dbb24be2bea0a
|
4
|
+
data.tar.gz: 22087e848ed37bf0551999ea9923248688a5194501be7d02d07e2a2448fe701d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21931a6cedf1dfb74539e19657a9df58becb94e098a94423a059c3961ee042f36a66b547c40bc62ca66b17498235330743f12f8bc3d75a1c6f5172b25df15d37
|
7
|
+
data.tar.gz: 0220b63454657b7cddd89100a2d1ebe940369d6c0749345153912676741eba50f48d6ec1ae5e68f1eed08c46f4fa4e6c77032a0b0839f46645e7a4b376ef9ac0
|
@@ -22,13 +22,59 @@ module Switchman
|
|
22
22
|
@integral_id
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
def transaction(**)
|
26
|
+
if self != ::ActiveRecord::Base && current_scope
|
27
|
+
current_scope.activate do
|
28
|
+
db = Shard.current(connection_class_for_self).database_server
|
29
|
+
db.unguard { super }
|
30
|
+
end
|
31
|
+
else
|
32
|
+
db = Shard.current(connection_class_for_self).database_server
|
33
|
+
db.unguard { super }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# NOTE: `returning` values are _not_ transposed back to the current shard
|
38
|
+
%w[insert_all upsert_all].each do |method|
|
26
39
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
27
|
-
def #{method}(
|
28
|
-
|
29
|
-
|
40
|
+
def #{method}(attributes, returning: nil, **)
|
41
|
+
scope = self != ::ActiveRecord::Base && current_scope
|
42
|
+
if (target_shard = scope&.primary_shard) == (current_shard = Shard.current(connection_class_for_self))
|
43
|
+
scope = nil
|
44
|
+
end
|
45
|
+
if scope
|
46
|
+
dupped = false
|
47
|
+
attributes.each_with_index do |hash, i|
|
48
|
+
if dupped || hash.any? { |k, v| sharded_column?(k) }
|
49
|
+
unless dupped
|
50
|
+
attributes = attributes.dup
|
51
|
+
dupped = true
|
52
|
+
end
|
53
|
+
attributes[i] = hash.to_h do |k, v|
|
54
|
+
if sharded_column?(k)
|
55
|
+
[k, Shard.relative_id_for(v, current_shard, target_shard)]
|
56
|
+
else
|
57
|
+
[k, v]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if scope
|
65
|
+
scope.activate do
|
30
66
|
db = Shard.current(connection_class_for_self).database_server
|
31
|
-
db.unguard { super }
|
67
|
+
result = db.unguard { super }
|
68
|
+
if result&.columns&.any? { |c| sharded_column?(c) }
|
69
|
+
transposed_rows = result.rows.map do |row|
|
70
|
+
row.map.with_index do |value, i|
|
71
|
+
sharded_column?(result.columns[i]) ? Shard.relative_id_for(value, target_shard, current_shard) : value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
result = ::ActiveRecord::Result.new(result.columns, transposed_rows, result.column_types)
|
75
|
+
end
|
76
|
+
|
77
|
+
result
|
32
78
|
end
|
33
79
|
else
|
34
80
|
db = Shard.current(connection_class_for_self).database_server
|
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: 3.6.
|
4
|
+
version: 3.6.6
|
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: 2024-
|
13
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|