switchman 1.14.7 → 1.14.8
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_internal.rb +1 -1
- data/lib/switchman/active_record/association.rb +5 -1
- data/lib/switchman/active_record/base.rb +8 -0
- data/lib/switchman/active_record/connection_pool.rb +3 -3
- data/lib/switchman/connection_pool_proxy.rb +2 -2
- data/lib/switchman/default_shard.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: dab76e2ecd636e151a0cd1073bb2271fb54ed6051dbaecca170c89fb96de012c
|
4
|
+
data.tar.gz: f4537579439d2b6dc6ce8947edeaf80effb6af16eef20f13ef85b1e1803b80d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a502e2f21fa54eeb1a04589ed5695b2077039ba011e2ee04fc322bfca0107ddf923b0863748c6ab08a35cc910e7f5b880d052acbddaee75149fc031e8fd0fcbd
|
7
|
+
data.tar.gz: 66bb964e5622bf09aecee7a9f5404056185427468634f18001d0fae2dc188d119232f15ad7d2d7b071de7e86e0a4b0a80e8394ce4eafa5b3c571821c7b42cfa1
|
@@ -64,7 +64,7 @@ module Switchman
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# rebuild current shard activations - it might have "another" default shard serialized there
|
67
|
-
active_shards.replace(active_shards.map do |category, shard|
|
67
|
+
active_shards.replace(active_shards.dup.map do |category, shard|
|
68
68
|
shard = Shard.lookup((!shard || shard.default?) ? 'default' : shard.id)
|
69
69
|
[category, shard]
|
70
70
|
end.to_h)
|
@@ -88,7 +88,11 @@ module Switchman
|
|
88
88
|
# Copypasta from Activerecord but with added global_id_for goodness.
|
89
89
|
def records_for(ids)
|
90
90
|
scope.where(association_key_name => ids).load do |record|
|
91
|
-
global_key =
|
91
|
+
global_key = if record.class.shard_category == :unsharded
|
92
|
+
convert_key(record[association_key_name])
|
93
|
+
else
|
94
|
+
Shard.global_id_for(record[association_key_name], record.shard)
|
95
|
+
end
|
92
96
|
owner = owners_by_key[global_key.to_s].first
|
93
97
|
association = owner.association(reflection.name)
|
94
98
|
association.set_inverse_instance(record)
|
@@ -68,6 +68,14 @@ module Switchman
|
|
68
68
|
result
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
def clear_query_caches_for_current_thread
|
73
|
+
::ActiveRecord::Base.connection_handlers.each_value do |handler|
|
74
|
+
handler.connection_pool_list.each do |pool|
|
75
|
+
pool.connection(switch_shard: false).clear_query_cache if pool.active_connection?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
71
79
|
end
|
72
80
|
|
73
81
|
def self.included(klass)
|
@@ -32,10 +32,10 @@ module Switchman
|
|
32
32
|
conn
|
33
33
|
end
|
34
34
|
|
35
|
-
def connection
|
36
|
-
conn = super
|
35
|
+
def connection(switch_shard: true)
|
36
|
+
conn = super()
|
37
37
|
raise NonExistentShardError if shard.new_record?
|
38
|
-
switch_database(conn) if conn.shard != self.shard
|
38
|
+
switch_database(conn) if conn.shard != self.shard && switch_shard
|
39
39
|
conn
|
40
40
|
end
|
41
41
|
|
@@ -53,10 +53,10 @@ module Switchman
|
|
53
53
|
connection_pools.map(&:connections).inject([], &:+)
|
54
54
|
end
|
55
55
|
|
56
|
-
def connection
|
56
|
+
def connection(switch_shard: true)
|
57
57
|
pool = current_pool
|
58
58
|
begin
|
59
|
-
connection = pool.connection
|
59
|
+
connection = pool.connection(switch_shard: switch_shard)
|
60
60
|
connection.instance_variable_set(:@schema_cache, @schema_cache) unless ::Rails.version >= '6'
|
61
61
|
connection
|
62
62
|
rescue ConnectionError
|
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: 1.14.
|
4
|
+
version: 1.14.8
|
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: 2019-
|
13
|
+
date: 2019-11-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|