switchman 1.6.0 → 1.6.1

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: 5216239c0a0c3b84a975c7f5a7c63250a36c3960
4
- data.tar.gz: 9eff38ae0cdfe742c47d25667dfa9bd5f807ad44
3
+ metadata.gz: fb1dad0f6da4624a6946a25d2afb9a398fa101df
4
+ data.tar.gz: 27c1f2e00c09a1b585408144526de94ce438561b
5
5
  SHA512:
6
- metadata.gz: 1a8afa7d5bbedf8bf89d797cab7eab0285a36d01d7f1efada6fb6e7aabb459ee44abfb3f82bc9e043399cf943a95bb1bee6b2f932ea92e65b97d77d7c2510801
7
- data.tar.gz: fa08be1de119479e4e9a0ad3ac6f5c6a6a18f8c3400d2d784bf30be78aaff3665875eafb2a621bd2e3a4f6181affe95a49a74b6d73e55244c0810c7409b318da
6
+ metadata.gz: fdf18b474711a37ade96a52015f09d736725a030151e97b0ac341741c254f1816409f36d564d19a5d4fbd29cea585d69f7c7f64c7029bd7a99cf026515fd8a07
7
+ data.tar.gz: 80708161aeedbb40f42ca1f837ab9333f14a7a94d1d1ca3608c28bd1cbc655cbdc5471960a437f5c82a6a3813ce23008f7034b2374c2cafc16852822b2e20cec
@@ -251,7 +251,7 @@ module Switchman
251
251
 
252
252
  # only one process; don't bother forking
253
253
  if scopes.length == 1 && parallel == 1
254
- return with_each_shard(subscopes.first, categories, options) { yield }
254
+ return with_each_shard(scopes.first.last, categories, options) { yield }
255
255
  end
256
256
 
257
257
  # clear connections prior to forking (no more queries will be executed in the parent,
@@ -1,9 +1,27 @@
1
1
  module Switchman
2
2
  module ActiveRecord
3
3
  module FinderMethods
4
- def find_one(id)
4
+ def find_one(id, call_super: false)
5
+ return super(id) unless klass.integral_id?
6
+ return super(id) if call_super
7
+
5
8
  if shard_source_value != :implicit
6
- return self.activate { super(Shard.relative_id_for(id, Shard.current(klass.shard_category), primary_shard)) }
9
+ current_shard = Shard.current(klass.shard_category)
10
+ result = self.activate do |relation, shard|
11
+ current_id = Shard.relative_id_for(id, current_shard, shard)
12
+ # current_id will be nil for non-integral id
13
+ next unless current_id
14
+ # skip the shard if the object can't be on it. unless we're only looking at one shard;
15
+ # we might be expecting a shadow object
16
+ next if current_id > Shard::IDS_PER_SHARD && self.all_shards.length > 1
17
+ relation.send(:find_one, current_id, call_super: true)
18
+ end
19
+ if result.is_a?(Array)
20
+ result = result.first
21
+ end
22
+ # we may have skipped all shards
23
+ raise_record_not_found_exception!(id, 0, 1) unless result
24
+ return result
7
25
  end
8
26
 
9
27
  local_id, shard = Shard.local_id_for(id)
@@ -22,7 +40,7 @@ module Switchman
22
40
  shard.activate { super(local_id) }
23
41
  end
24
42
  else
25
- super
43
+ super(id)
26
44
  end
27
45
  end
28
46
 
@@ -53,7 +71,7 @@ module Switchman
53
71
 
54
72
  args = [relation, "#{name} Exists"]
55
73
  args << relation.bind_values if ::Rails.version >= '4.1'
56
- activate { return true if connection.select_value(*args) }
74
+ relation.activate { return true if connection.select_value(*args) }
57
75
  false
58
76
  rescue
59
77
  raise if ::Rails.version >= '4.1' || !(::ActiveRecord::ThrowResult === $!)
@@ -62,7 +62,7 @@ module Switchman
62
62
  when Hash, ::Arel::Nodes::Node
63
63
  predicates = super
64
64
  infer_shards_from_primary_key(predicates) if shard_source_value == :implicit && shard_value.is_a?(Shard)
65
- predicates = transpose_predicates(predicates, nil, primary_shard) if shard_source_value != :explicit
65
+ predicates = transpose_predicates(predicates, nil, primary_shard)
66
66
  predicates
67
67
  else
68
68
  super
@@ -284,6 +284,8 @@ module Switchman
284
284
  current_source_shard =
285
285
  if source_shard
286
286
  source_shard
287
+ elsif shard_source_value == :explicit
288
+ primary_shard
287
289
  elsif type == :primary
288
290
  Shard.current(klass.shard_category)
289
291
  elsif type == :foreign
@@ -21,7 +21,7 @@ module Switchman
21
21
  where_clause = super
22
22
  predicates = where_clause.send(:predicates)
23
23
  @scope.send(:infer_shards_from_primary_key, predicates, where_clause.binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard)
24
- predicates = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, where_clause.binds) if @scope.shard_source_value != :explicit
24
+ predicates = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, where_clause.binds)
25
25
  where_clause.instance_variable_set(:@predicates, predicates)
26
26
  where_clause
27
27
  else
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
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.6.0
4
+ version: 1.6.1
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-09-13 00:00:00.000000000 Z
13
+ date: 2016-09-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project:
229
- rubygems_version: 2.4.5.1
229
+ rubygems_version: 2.6.4
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: Rails 4 sharding magic