switchman 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/switchman/active_record/association.rb +1 -2
- data/lib/switchman/active_record/base.rb +1 -1
- data/lib/switchman/active_record/core.rb +18 -0
- data/lib/switchman/active_record/statement_cache.rb +2 -2
- data/lib/switchman/engine.rb +2 -0
- data/lib/switchman/shard_aware_statement_cache.rb +21 -0
- data/lib/switchman/version.rb +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f1b18d5c70d7c7c0db5295eecc955e89eb7ffc
|
4
|
+
data.tar.gz: 9c87565145d1c2d28319c5dd0fcfba2be42d63e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5c427e9b504ba9f24407e635e59d4b53fe898666095390b18049ce17831aa72387bbf04fa4996face96ee1a958f861441a5064f7acc9c79c96f40fd38631d87
|
7
|
+
data.tar.gz: 23e544a6a514824bdca90f51a12de4832b350a1b63adba3569ec73bd51da8c5267b8b71e53685197330e37973c284314a7895764ee47e91e29892d1d46246afd
|
@@ -115,10 +115,9 @@ module Switchman
|
|
115
115
|
# for multishard associations, it's the owner object itself
|
116
116
|
# (all associated shards)
|
117
117
|
|
118
|
-
# this is the default behavior of partition_by_shard, so just
|
118
|
+
# this is the default behavior of partition_by_shard, so just let it be nil
|
119
119
|
# to avoid the proc call
|
120
120
|
# partition_proc = ->(owner) { owner }
|
121
|
-
partitition_proc = nil
|
122
121
|
end
|
123
122
|
|
124
123
|
records = Shard.partition_by_shard(owners, partition_proc) do |partitioned_owners|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "switchman/shard_aware_statement_cache"
|
2
|
+
|
3
|
+
module Switchman
|
4
|
+
module ActiveRecord
|
5
|
+
module Core
|
6
|
+
def initialize_find_by_cache
|
7
|
+
if ::Rails.version < '5'
|
8
|
+
self.find_by_statement_cache = ShardAwareStatementCache.new(shard_category)
|
9
|
+
else
|
10
|
+
# note that this will not work beyond ActiveRecord 5.0.0.beta3 since
|
11
|
+
# as of beta4 this has been replaced with a hash containing two separate caches:
|
12
|
+
# one for prepared statements, and one for unprepared ones
|
13
|
+
@find_by_statement_cache = ShardAwareStatementCache.new(shard_category)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -15,7 +15,7 @@ module Switchman
|
|
15
15
|
current_shard = Shard.current(klass.shard_category)
|
16
16
|
target_shard ||= current_shard
|
17
17
|
|
18
|
-
bind_values = bind_map.bind(params, current_shard, target_shard
|
18
|
+
bind_values = bind_map.bind(params, current_shard, target_shard)
|
19
19
|
|
20
20
|
sql = query_builder.sql_for(bind_values, connection)
|
21
21
|
target_shard.activate(klass.shard_category) do
|
@@ -69,4 +69,4 @@ module Switchman
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
data/lib/switchman/engine.rb
CHANGED
@@ -93,9 +93,11 @@ module Switchman
|
|
93
93
|
|
94
94
|
if ::Rails.version > '4.2'
|
95
95
|
require "switchman/active_record/statement_cache"
|
96
|
+
require "switchman/active_record/core"
|
96
97
|
::ActiveRecord::StatementCache.prepend(ActiveRecord::StatementCache)
|
97
98
|
::ActiveRecord::StatementCache::BindMap.prepend(ActiveRecord::StatementCache::BindMap)
|
98
99
|
::ActiveRecord::StatementCache::Substitute.send(:attr_accessor, :primary, :sharded)
|
100
|
+
singleton_class.prepend ActiveRecord::Core
|
99
101
|
|
100
102
|
::ActiveRecord::Associations::CollectionAssociation.prepend(ActiveRecord::CollectionAssociation)
|
101
103
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Switchman
|
2
|
+
class ShardAwareStatementCache
|
3
|
+
|
4
|
+
attr_accessor :__cache, :shard_category
|
5
|
+
private :__cache, :shard_category
|
6
|
+
|
7
|
+
def initialize(shard_category)
|
8
|
+
self.extend Mutex_m
|
9
|
+
self.__cache = {}
|
10
|
+
self.shard_category = shard_category
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](key)
|
14
|
+
__cache[[key, Shard.current(shard_category).id]]
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(key, value)
|
18
|
+
__cache[[key, Shard.current(shard_category).id]] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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.5
|
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-05-
|
13
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -19,9 +19,9 @@ dependencies:
|
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '4.0'
|
22
|
-
- - "
|
22
|
+
- - "<="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 5.0.0.beta3
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,9 +29,9 @@ dependencies:
|
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: '4.0'
|
32
|
-
- - "
|
32
|
+
- - "<="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 5.0.0.beta3
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activerecord
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,9 +39,9 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '4.0'
|
42
|
-
- - "
|
42
|
+
- - "<="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: 5.0.0.beta3
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,9 +49,9 @@ dependencies:
|
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '4.0'
|
52
|
-
- - "
|
52
|
+
- - "<="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 5.0.0.beta3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: shackles
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/switchman/active_record/calculations.rb
|
172
172
|
- lib/switchman/active_record/connection_handler.rb
|
173
173
|
- lib/switchman/active_record/connection_pool.rb
|
174
|
+
- lib/switchman/active_record/core.rb
|
174
175
|
- lib/switchman/active_record/finder_methods.rb
|
175
176
|
- lib/switchman/active_record/log_subscriber.rb
|
176
177
|
- lib/switchman/active_record/model_schema.rb
|
@@ -200,6 +201,7 @@ files:
|
|
200
201
|
- lib/switchman/schema_cache.rb
|
201
202
|
- lib/switchman/shackles.rb
|
202
203
|
- lib/switchman/shackles/relation.rb
|
204
|
+
- lib/switchman/shard_aware_statement_cache.rb
|
203
205
|
- lib/switchman/sharded_instrumenter.rb
|
204
206
|
- lib/switchman/test_helper.rb
|
205
207
|
- lib/switchman/version.rb
|
@@ -224,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
226
|
version: '0'
|
225
227
|
requirements: []
|
226
228
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
229
|
+
rubygems_version: 2.5.1
|
228
230
|
signing_key:
|
229
231
|
specification_version: 4
|
230
232
|
summary: Rails 4 sharding magic
|