switchman 2.1.2 → 2.1.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/app/models/switchman/shard.rb +5 -0
- data/lib/switchman/active_record/attribute_methods.rb +11 -1
- data/lib/switchman/active_record/base.rb +11 -11
- data/lib/switchman/active_record/persistence.rb +10 -1
- data/lib/switchman/active_record/postgresql_adapter.rb +1 -1
- data/lib/switchman/engine.rb +1 -1
- data/lib/switchman/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a8870f7b32fb16b98edcd9cd0930c30359df0a71a73ecc63752b256b5ac616
|
4
|
+
data.tar.gz: 90a3f31b1b8c5951720c7a45a3418c8448a5e08160939de73d487bfd8c9a7dc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017200b98b0c53d0004c2632322e63141284716609b50400bf5936bf776aa06a68a648e1ff11df0d2d715e1993e051ea0e103c0356d0658ff121283447a376e7
|
7
|
+
data.tar.gz: 50cb3e155dd07d2d5e9171f788abce42b29b39d1f488d75cb97ae75842eda94876c4a9b0af134f1b0e03094bc14358c4b9ccc0677a83ebff741d948b9b496d5e
|
@@ -129,6 +129,11 @@ module Switchman
|
|
129
129
|
cached_shards[id]
|
130
130
|
end
|
131
131
|
|
132
|
+
def preload_cache
|
133
|
+
cached_shards.reverse_merge!(active_shards.values.index_by(&:id))
|
134
|
+
cached_shards.reverse_merge!(all.index_by(&:id))
|
135
|
+
end
|
136
|
+
|
132
137
|
def clear_cache
|
133
138
|
cached_shards.clear
|
134
139
|
end
|
@@ -103,8 +103,18 @@ module Switchman
|
|
103
103
|
def __temp_relative_attribute__
|
104
104
|
raw_value = original_#{attr_name}
|
105
105
|
return nil if raw_value.nil?
|
106
|
+
|
107
|
+
abs_raw_value = raw_value.abs
|
106
108
|
current_shard = Shard.current(#{shard_category_code_for_reflection(reflection)})
|
107
|
-
|
109
|
+
same_shard = shard == current_shard
|
110
|
+
return raw_value if same_shard && abs_raw_value < Shard::IDS_PER_SHARD
|
111
|
+
|
112
|
+
value_shard_id = abs_raw_value / Shard::IDS_PER_SHARD
|
113
|
+
# this is a stupid case when someone stuffed a global id for the current shard in instead
|
114
|
+
# of a local id
|
115
|
+
return raw_value % Shard::IDS_PER_SHARD if value_shard_id == current_shard.id
|
116
|
+
return raw_value if !same_shard && abs_raw_value > Shard::IDS_PER_SHARD
|
117
|
+
return shard.global_id_for(raw_value) if !same_shard && abs_raw_value < Shard::IDS_PER_SHARD
|
108
118
|
|
109
119
|
Shard.relative_id_for(raw_value, shard, current_shard)
|
110
120
|
end
|
@@ -80,17 +80,17 @@ module Switchman
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
def self.
|
84
|
-
klass.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
83
|
+
def self.prepended(klass)
|
84
|
+
klass.singleton_class.prepend(ClassMethods)
|
85
|
+
end
|
86
|
+
|
87
|
+
def _run_initialize_callbacks
|
88
|
+
@shard ||= if self.class.sharded_primary_key?
|
89
|
+
Shard.shard_for(self[self.class.primary_key], Shard.current(self.class.shard_category))
|
90
|
+
else
|
91
|
+
Shard.current(self.class.shard_category)
|
93
92
|
end
|
93
|
+
super
|
94
94
|
end
|
95
95
|
|
96
96
|
def shard
|
@@ -158,7 +158,7 @@ module Switchman
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def update_columns(*)
|
161
|
-
db =
|
161
|
+
db = shard.database_server
|
162
162
|
if ::GuardRail.environment != db.guard_rail_environment
|
163
163
|
return db.unguard { super }
|
164
164
|
else
|
@@ -13,6 +13,15 @@ module Switchman
|
|
13
13
|
shard.activate(self.class.shard_category) { super }
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
def delete
|
18
|
+
db = shard.database_server
|
19
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
20
|
+
return db.unguard { super }
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
16
25
|
end
|
17
26
|
end
|
18
|
-
end
|
27
|
+
end
|
@@ -102,7 +102,7 @@ module Switchman
|
|
102
102
|
WHERE i.relkind = 'i'
|
103
103
|
AND d.indisprimary = 'f'
|
104
104
|
AND t.relname = '#{table_name}'
|
105
|
-
AND
|
105
|
+
AND t.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = '#{shard.name}' )
|
106
106
|
ORDER BY i.relname
|
107
107
|
SQL
|
108
108
|
|
data/lib/switchman/engine.rb
CHANGED
@@ -95,7 +95,7 @@ module Switchman
|
|
95
95
|
|
96
96
|
::StandardError.include(StandardError)
|
97
97
|
|
98
|
-
|
98
|
+
prepend ActiveRecord::Base
|
99
99
|
include ActiveRecord::AttributeMethods
|
100
100
|
include ActiveRecord::Persistence
|
101
101
|
singleton_class.prepend ActiveRecord::ModelSchema::ClassMethods
|
data/lib/switchman/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
- James Williams
|
9
9
|
- Jacob Fugal
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -257,7 +257,7 @@ homepage: http://www.instructure.com/
|
|
257
257
|
licenses:
|
258
258
|
- MIT
|
259
259
|
metadata: {}
|
260
|
-
post_install_message:
|
260
|
+
post_install_message:
|
261
261
|
rdoc_options: []
|
262
262
|
require_paths:
|
263
263
|
- lib
|
@@ -272,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
- !ruby/object:Gem::Version
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
|
-
rubygems_version: 3.
|
276
|
-
signing_key:
|
275
|
+
rubygems_version: 3.2.24
|
276
|
+
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Rails sharding magic
|
279
279
|
test_files: []
|