switchman 1.9.1 → 1.9.2

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: 33042670de931ff4d9974370cf8703bc2059f53b
4
- data.tar.gz: b3ef2ecf2944446cfd06617b85179e2c20ddadb4
3
+ metadata.gz: fa3506567faae98c3df18544db429163ea0aed03
4
+ data.tar.gz: 8f354e57d9ce1342ce2f369a13fe485f92f6dcfa
5
5
  SHA512:
6
- metadata.gz: 39f9d4473a0a544110c89b8d4c9253c651bb9b08d0e3042c605ea7b1bbf39a304a19790b43bede1a44e172756175f5d88f01de3662354eeaab7ced5a61d3bdfd
7
- data.tar.gz: 4341cb78497d39d27f94d1026d45a99a7815fe96645a90692a325dca5d161229cef5ba3fd1f55c07f7729fbd9ab359827cf96b9477f4d03f644d27c1b0443404
6
+ metadata.gz: 4a9c5fb4a816d4e76f2991b5d39b23182c055d34771016edaeb181dda77c1f0c99c542d23fad4629b7d3ccc2202fa7954faf38b0006f76a333817a7b6e6dbd7b
7
+ data.tar.gz: 2e05febfa8a714552cbb27cdb0fb223d5c8442de344fb3cba606a5c4a566cac6a47df34d362991524ed5a0591a6d3e188666a33cbf3ab7b0874187488c2035d9
@@ -198,7 +198,7 @@ module Switchman
198
198
  scopes = Hash[database_servers.map do |server|
199
199
  server_scope = server.shards.merge(scope)
200
200
  if parallel == 1
201
- subscopes = server_scope
201
+ subscopes = [server_scope]
202
202
  else
203
203
  subscopes = []
204
204
  total = server_scope.count
@@ -223,6 +223,8 @@ module Switchman
223
223
  scopes = Hash[scopes.map do |(server, shards)|
224
224
  [server, shards.in_groups(parallel, false).compact]
225
225
  end]
226
+ else
227
+ scopes = Hash[scopes.map { |(server, shards)| [server, [shards]] }]
226
228
  end
227
229
  end
228
230
 
@@ -250,7 +252,7 @@ module Switchman
250
252
 
251
253
  # only one process; don't bother forking
252
254
  if scopes.length == 1 && parallel == 1
253
- return with_each_shard(scopes.first.last, categories, options) { yield }
255
+ return with_each_shard(scopes.first.last.first, categories, options) { yield }
254
256
  end
255
257
 
256
258
  # clear connections prior to forking (no more queries will be executed in the parent,
@@ -259,10 +261,6 @@ module Switchman
259
261
  ::ActiveRecord::Base.clear_all_connections!
260
262
 
261
263
  scopes.each do |server, subscopes|
262
- if !(::ActiveRecord::Relation === subscopes.first) && subscopes.first.class != Array
263
- subscopes = [subscopes]
264
- end
265
-
266
264
  subscopes.each_with_index do |subscope, idx|
267
265
  if subscopes.length > 1
268
266
  name = "#{server.id} #{idx + 1}"
@@ -274,7 +272,7 @@ module Switchman
274
272
  exception_pipes << exception_pipe
275
273
  pid, io_in, io_out, io_err = Open4.pfork4(lambda do
276
274
  begin
277
- Switchman.config[:on_fork_proc].try(:call)
275
+ Switchman.config[:on_fork_proc]&.call
278
276
  $0 = [$0, ARGV, name].flatten.join(' ')
279
277
  with_each_shard(subscope, categories, options) { yield }
280
278
  exception_pipe.last.close
@@ -610,7 +608,7 @@ module Switchman
610
608
  begin
611
609
  adapter = self.database_server.config[:adapter]
612
610
  sharding_config = Switchman.config || {}
613
- drop_statement = sharding_config[adapter].try(:[], :drop_statement)
611
+ drop_statement = sharding_config[adapter]&.[](:drop_statement)
614
612
  drop_statement ||= sharding_config[:drop_statement]
615
613
  if drop_statement
616
614
  drop_statement = Array(drop_statement).dup.
@@ -27,7 +27,7 @@ module Switchman
27
27
  def reflection_for_integer_attribute(attr_name)
28
28
  attr_name = attr_name.to_s
29
29
  columns_hash[attr_name] && columns_hash[attr_name].type == :integer &&
30
- reflections.find { |_, r| r.belongs_to? && r.foreign_key.to_s == attr_name }.try(:last)
30
+ reflections.find { |_, r| r.belongs_to? && r.foreign_key.to_s == attr_name }&.last
31
31
  rescue ::ActiveRecord::StatementInvalid
32
32
  # this is for when models are referenced in initializers before migrations have been run
33
33
  raise if connection.open_transactions > 0
@@ -65,8 +65,8 @@ module Switchman
65
65
  if reflection
66
66
  if reflection.options[:polymorphic]
67
67
  # a polymorphic association has to be discovered at runtime. This code ends up being something like
68
- # context_type.try(:constantize).try(:shard_category) || :primary
69
- "read_attribute(:#{reflection.foreign_type}).try(:constantize).try(:shard_category) || :primary"
68
+ # context_type.&.constantize&.shard_category || :primary
69
+ "read_attribute(:#{reflection.foreign_type})&.constantize&.shard_category || :primary"
70
70
  else
71
71
  # otherwise we can just return a symbol for the statically known type of the association
72
72
  reflection.klass.shard_category.inspect
@@ -33,7 +33,7 @@ module Switchman
33
33
 
34
34
  def integral_id?
35
35
  if @integral_id == nil
36
- @integral_id = columns_hash[primary_key].try(:type) == :integer
36
+ @integral_id = columns_hash[primary_key]&.type == :integer
37
37
  end
38
38
  @integral_id
39
39
  end
@@ -44,7 +44,7 @@ module Switchman
44
44
  end
45
45
 
46
46
  def clear_query_cache
47
- Thread.current[:query_cache].try(:clear)
47
+ Thread.current[:query_cache]&.clear
48
48
  end
49
49
 
50
50
  def select_all(arel, name = nil, binds = [], preparable: nil)
@@ -182,14 +182,14 @@ module Switchman
182
182
  # look for a bind param with a matching column name
183
183
  if ::Rails.version >= "5"
184
184
  binds ||= where_clause.binds + having_clause.binds
185
- if binds && bind = binds.detect{|b| b.try(:name).to_s == klass.primary_key.to_s}
185
+ if binds && bind = binds.detect{|b| b&.name.to_s == klass.primary_key.to_s}
186
186
  unless bind.value.is_a?(::ActiveRecord::StatementCache::Substitute)
187
187
  local_id, id_shard = Shard.local_id_for(bind.value)
188
188
  id_shard ||= Shard.current(klass.shard_category) if local_id
189
189
  end
190
190
  end
191
191
  else
192
- if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first.try(:name).to_s == klass.primary_key.to_s}
192
+ if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first&.name.to_s == klass.primary_key.to_s}
193
193
  column, value = bind_values[idx]
194
194
  unless value.is_a?(::ActiveRecord::StatementCache::Substitute)
195
195
  local_id, id_shard = Shard.local_id_for(value)
@@ -313,7 +313,7 @@ module Switchman
313
313
  # look for a bind param with a matching column name
314
314
  if ::Rails.version >= "5"
315
315
  binds ||= where_clause.binds + having_clause.binds
316
- if binds && bind = binds.detect{|b| b.try(:name).to_s == predicate.left.name.to_s}
316
+ if binds && bind = binds.detect{|b| b&.name.to_s == predicate.left.name.to_s}
317
317
  if bind.value.is_a?(::ActiveRecord::StatementCache::Substitute)
318
318
  bind.value.sharded = true # mark for transposition later
319
319
  bind.value.primary = true if type == :primary
@@ -325,7 +325,7 @@ module Switchman
325
325
  end
326
326
  end
327
327
  else
328
- if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first.try(:name).to_s == predicate.left.name.to_s}
328
+ if bind_values && idx = bind_values.find_index{|b| b.is_a?(Array) && b.first&.name.to_s == predicate.left.name.to_s}
329
329
  column, value = bind_values[idx]
330
330
  if value.is_a?(::ActiveRecord::StatementCache::Substitute)
331
331
  value.sharded = true # mark for transposition later
@@ -134,7 +134,7 @@ module Switchman
134
134
  create_schema = options[:schema]
135
135
  # look for another shard associated with this db
136
136
  other_shard = self.shards.where("name<>':memory:' OR name IS NULL").order(:id).first
137
- temp_name = other_shard.try(:name) unless id == ::Rails.env
137
+ temp_name = other_shard&.name unless id == ::Rails.env
138
138
  temp_name = Shard.default.name if id == ::Rails.env
139
139
 
140
140
  case config[:adapter]
@@ -158,7 +158,7 @@ module Switchman
158
158
  create_statement = lambda { "CREATE DATABASE #{name}" }
159
159
  end
160
160
  sharding_config = Switchman.config
161
- config_create_statement = sharding_config[config[:adapter]].try(:[], :create_statement)
161
+ config_create_statement = sharding_config[config[:adapter]]&.[](:create_statement)
162
162
  config_create_statement ||= sharding_config[:create_statement]
163
163
  if config_create_statement
164
164
  create_commands = Array(config_create_statement).dup
@@ -6,7 +6,7 @@ module Switchman
6
6
  end
7
7
 
8
8
  def instrument(name, payload={})
9
- shard = @shard_host.try(:shard)
9
+ shard = @shard_host&.shard
10
10
  # attribute_methods_generated? will be false during a reload -
11
11
  # when we might be doing a query while defining attribute methods,
12
12
  # so just avoid logging then
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.9.1"
2
+ VERSION = "1.9.2"
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.9.1
4
+ version: 1.9.2
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-12-09 00:00:00.000000000 Z
13
+ date: 2016-12-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties