switchman 1.5.10 → 1.5.11
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6e7bdc0136ef65434df5ec4cd150a80ea3ff48a
|
4
|
+
data.tar.gz: 3ac58daa39eb55bc3b1ea743d6995072acf91ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792fbbdedbdc2028003b2eda51934e9c8821d0fd479c7e5da119c453d3696f232a752bcef868c291f3cc4b31a7acf560cadfda50c4bd48df4aa64826eb27b1f3
|
7
|
+
data.tar.gz: 1310d057a27d42f01a7dbad5b70d6ac3be09b42aa06f3abd71f3c933260a387b3542e97a2ca5754b0bd89ee65f0689f7314f8717e5a8929c676dad24879c5ef3
|
@@ -3,10 +3,12 @@ require 'switchman/errors'
|
|
3
3
|
module Switchman
|
4
4
|
module ActiveRecord
|
5
5
|
module ConnectionPool
|
6
|
-
attr_writer :shard
|
7
|
-
|
8
6
|
def shard
|
9
|
-
|
7
|
+
Thread.current["#{object_id}_shard".to_sym] || Shard.default
|
8
|
+
end
|
9
|
+
|
10
|
+
def shard=(value)
|
11
|
+
Thread.current["#{object_id}_shard".to_sym] = value
|
10
12
|
end
|
11
13
|
|
12
14
|
def default_schema
|
@@ -18,10 +20,14 @@ module Switchman
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def checkout_new_connection
|
21
|
-
|
22
|
-
|
23
|
+
conn = synchronize do
|
24
|
+
# ideally I would just keep a thread-local spec that I could modify
|
25
|
+
# without locking anything, but if spec returns not-the-object passed
|
26
|
+
# to initialize this pool, things break
|
27
|
+
spec.config[:shard_name] = self.shard.name
|
23
28
|
|
24
|
-
|
29
|
+
super
|
30
|
+
end
|
25
31
|
conn.shard = self.shard
|
26
32
|
conn
|
27
33
|
end
|
@@ -71,7 +71,7 @@ module Switchman
|
|
71
71
|
when ::ActiveRecord::Relation
|
72
72
|
Shard.default
|
73
73
|
when nil
|
74
|
-
Shard.current(klass.
|
74
|
+
Shard.current(klass.shard_category)
|
75
75
|
else
|
76
76
|
raise ArgumentError, "invalid shard value #{shard_value}"
|
77
77
|
end
|
@@ -85,7 +85,7 @@ module Switchman
|
|
85
85
|
when ::ActiveRecord::Base
|
86
86
|
shard_value.respond_to?(:associated_shards) ? shard_value.associated_shards : [shard_value.shard]
|
87
87
|
when nil
|
88
|
-
[Shard.current(klass.
|
88
|
+
[Shard.current(klass.shard_category)]
|
89
89
|
else
|
90
90
|
shard_value
|
91
91
|
end
|
@@ -13,6 +13,20 @@ module Switchman
|
|
13
13
|
owner.send(active_record_primary_key) # use sharded id values in association binds
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
# cache association scopes by shard.
|
18
|
+
if ::Rails.version >= '4.2'
|
19
|
+
def association_scope_cache(conn, owner)
|
20
|
+
key = conn.prepared_statements
|
21
|
+
if polymorphic?
|
22
|
+
key = [key, owner._read_attribute(@foreign_type)]
|
23
|
+
end
|
24
|
+
key = [key, owner.shard.id].flatten
|
25
|
+
@association_scope_cache[key] ||= @scope_lock.synchronize {
|
26
|
+
@association_scope_cache[key] ||= yield
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
@@ -7,13 +7,13 @@ module Switchman
|
|
7
7
|
|
8
8
|
def initialize(*args)
|
9
9
|
super
|
10
|
-
self.shard_value = Shard.current(klass
|
10
|
+
self.shard_value = Shard.current(klass ? klass.shard_category : :default) unless shard_value
|
11
11
|
self.shard_source_value = :implicit unless shard_source_value
|
12
12
|
end
|
13
13
|
|
14
14
|
def clone
|
15
15
|
result = super
|
16
|
-
result.shard_value = Shard.current(klass
|
16
|
+
result.shard_value = Shard.current(klass ? klass.shard_category : :default) unless shard_value
|
17
17
|
result
|
18
18
|
end
|
19
19
|
|
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.5.
|
4
|
+
version: 1.5.11
|
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: 2016-06-
|
13
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
requirements: []
|
227
227
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.4
|
228
|
+
rubygems_version: 2.6.4
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: Rails 4 sharding magic
|