switchman 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ac20dcf634164e03ce0325d01a492a6b9f37ea6
|
4
|
+
data.tar.gz: c6e4c46ce8b9dbc04a39678cbd892e7f4ab1e852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed3e8db98ce052fbd21cead9d100cadc1822d20c5fa37eaee88d91bb25e9caedee72f0ce3f160b3d106359814796b43459a851e71e420cafe2ea1f8181a997a
|
7
|
+
data.tar.gz: 0f25cdd4c7c85f4ffd6d7c32ebfc0262d2c9593788ebebaaf71d970cfaa947ea47ba2bf40fc9d4834f06b941586ba355123cfd99952367a23b95ba68cb0829ae
|
@@ -2,12 +2,7 @@ module Switchman
|
|
2
2
|
module ActiveRecord
|
3
3
|
module Association
|
4
4
|
def shard
|
5
|
-
|
6
|
-
# polymorphic associations assume the same shard as the owning item
|
7
|
-
@owner.shard
|
8
|
-
else
|
9
|
-
Shard.default
|
10
|
-
end
|
5
|
+
reflection.shard(owner)
|
11
6
|
end
|
12
7
|
|
13
8
|
def build_record(*args)
|
@@ -42,8 +37,10 @@ module Switchman
|
|
42
37
|
|
43
38
|
module CollectionAssociation
|
44
39
|
def get_records
|
45
|
-
shards = reflection.options[:multishard] && owner.respond_to?(:associated_shards) ? owner.associated_shards : [
|
46
|
-
|
40
|
+
shards = reflection.options[:multishard] && owner.respond_to?(:associated_shards) ? owner.associated_shards : [shard]
|
41
|
+
# activate both the owner and the target's shard category, so that Reflection#join_id_for,
|
42
|
+
# when called for the owner, will be returned relative to shard the query will execute on
|
43
|
+
Shard.with_each_shard(shards, [klass.shard_category, owner.class.shard_category].uniq) do
|
47
44
|
super
|
48
45
|
end
|
49
46
|
end
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module Switchman
|
2
2
|
module ActiveRecord
|
3
3
|
module Reflection
|
4
|
+
module AbstractReflection
|
5
|
+
def shard(owner)
|
6
|
+
if polymorphic? || klass.shard_category == owner.class.shard_category
|
7
|
+
# polymorphic associations assume the same shard as the owning item
|
8
|
+
owner.shard
|
9
|
+
else
|
10
|
+
Shard.default
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
4
15
|
module AssociationReflection
|
5
16
|
# removes memoization - ActiveRecord::ModelSchema does that anyway;
|
6
17
|
# and in fact this is the exact change AR makes in 4.2+
|
@@ -21,7 +32,7 @@ module Switchman
|
|
21
32
|
if polymorphic?
|
22
33
|
key = [key, owner._read_attribute(@foreign_type)]
|
23
34
|
end
|
24
|
-
key = [key, owner.
|
35
|
+
key = [key, shard(owner).id].flatten
|
25
36
|
@association_scope_cache[key] ||= @scope_lock.synchronize {
|
26
37
|
@association_scope_cache[key] ||= yield
|
27
38
|
}
|
data/lib/switchman/engine.rb
CHANGED
@@ -132,6 +132,11 @@ module Switchman
|
|
132
132
|
::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
|
133
133
|
|
134
134
|
::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
|
135
|
+
if ::Rails.version >= '4.2'
|
136
|
+
::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
|
137
|
+
else
|
138
|
+
::ActiveRecord::Reflection::AssociationReflection.include(ActiveRecord::Reflection::AbstractReflection)
|
139
|
+
end
|
135
140
|
::ActiveRecord::Reflection::AssociationReflection.prepend(ActiveRecord::Reflection::AssociationReflection)
|
136
141
|
::ActiveRecord::Relation.prepend(ActiveRecord::Batches)
|
137
142
|
::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
|
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.7.
|
4
|
+
version: 1.7.3
|
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-10-
|
13
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
requirements: []
|
256
256
|
rubyforge_project:
|
257
|
-
rubygems_version: 2.
|
257
|
+
rubygems_version: 2.5.1
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: Rails 4 sharding magic
|