switchman 3.0.7 → 3.0.10

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
  SHA256:
3
- metadata.gz: 326fba116e3a3801cdd40b47ede332a372dab86522cbeaab1a3b6b361eccce1f
4
- data.tar.gz: 190457646d607aa444dbff867c67c5cd854817e8105efab44dd00fc782d1f21e
3
+ metadata.gz: e0148847d4a814e96ae663f5e2576e52a5feb9709a0b4ca7edf531884404e982
4
+ data.tar.gz: df40d39aed43999ba851a99b74808704c99f536ef352194734a66b912c260564
5
5
  SHA512:
6
- metadata.gz: 3843b4407a36b8f7f3aff2381dc6ee2e5f886169349794e679759a6d13d96b52e96e832caf78728f20df7d1d017701d7e7d8847c8a4620cd6b669ba8f25e9cc6
7
- data.tar.gz: 8e667cd250473f5b885fea29888454a186bafa9f694138bf0cf9f6761962ef4bf2a85b595a9cd7d26fb3f6532b4b8b8be9d6362c01329a63f94272f63ee55b4b
6
+ metadata.gz: 04e37250e9480e5c1d4683259c2cf5380e7da23bf44d890550920a0446a1dd3dfc1f371b294ccea6d25a3cd54b8605d8a1277613cba953e5b3d23325580d2fd2
7
+ data.tar.gz: c8b4d479438201645fd5fab3997258e7e7e141680d2470ed2accef6922f32b664c9349e18b72b07e9a0fcf1366b47043deaf002feeadd3517138356a213010e9
@@ -43,11 +43,9 @@ module Switchman
43
43
  @default = begin
44
44
  find_cached('default_shard') { Shard.where(default: true).take } || default
45
45
  # If we are *super* early in boot, the connection pool won't exist; we don't want to fill in the default shard yet
46
- rescue ::ActiveRecord::ConnectionNotEstablished
47
- nil
48
- # rescue the fake default if the table doesn't exist
46
+ # Otherwise, rescue the fake default if the table doesn't exist
49
47
  rescue
50
- default
48
+ sharding_initialized ? default : nil
51
49
  end
52
50
  return default unless @default
53
51
 
@@ -469,6 +467,10 @@ module Switchman
469
467
 
470
468
  private
471
469
 
470
+ def sharding_initialized
471
+ @sharding_initialized ||= false
472
+ end
473
+
472
474
  def add_sharded_model(klass)
473
475
  @sharded_models = (sharded_models + [klass]).freeze
474
476
  initialize_sharding
@@ -496,6 +498,8 @@ module Switchman
496
498
 
497
499
  klass.connects_to shards: connects_to_hash
498
500
  end
501
+
502
+ @sharding_initialized = true
499
503
  end
500
504
 
501
505
  # in-process caching
@@ -21,7 +21,7 @@ module Switchman
21
21
  base_db = build_db_config_from_raw_config(env_name, name, base_config)
22
22
  [base_db] + roles.map do |role|
23
23
  build_db_config_from_raw_config(env_name, "#{env_name}/#{role}",
24
- base_config.merge(config[role]).merge(replica: true))
24
+ base_config.merge(config[role]))
25
25
  end
26
26
  end
27
27
 
@@ -270,11 +270,11 @@ module Switchman
270
270
  right_node = or_expr.right
271
271
  new_left_predicates = transpose_single_predicate(left_node, source_shard,
272
272
  target_shard, remove_nonlocal_primary_keys: remove_nonlocal_primary_keys)
273
- or_expr.instance_variable_set(:@left, new_left_predicates) if new_left_predicates != left_node
274
273
  new_right_predicates = transpose_single_predicate(right_node, source_shard,
275
274
  target_shard, remove_nonlocal_primary_keys: remove_nonlocal_primary_keys)
276
- or_expr.instance_variable_set(:@right, new_right_predicates) if new_right_predicates != right_node
277
- return predicate
275
+ return predicate if new_left_predicates == left_node && new_right_predicates == right_node
276
+
277
+ return ::Arel::Nodes::Grouping.new ::Arel::Nodes::Or.new(new_left_predicates, new_right_predicates)
278
278
  end
279
279
  return predicate unless predicate.is_a?(::Arel::Nodes::Binary) || predicate.is_a?(::Arel::Nodes::HomogeneousIn)
280
280
  return predicate unless predicate.left.is_a?(::Arel::Attributes::Attribute)
@@ -11,22 +11,44 @@ module Switchman
11
11
  module Visitors
12
12
  module ToSql
13
13
  # rubocop:disable Naming/MethodName
14
+ # rubocop:disable Naming/MethodParameterName
14
15
 
15
- def visit_Arel_Nodes_TableAlias(*args)
16
- o, collector = args
16
+ def visit_Arel_Nodes_TableAlias(o, collector)
17
17
  collector = visit o.relation, collector
18
18
  collector << ' '
19
19
  collector << quote_local_table_name(o.name)
20
20
  end
21
21
 
22
- def visit_Arel_Attributes_Attribute(*args)
23
- o = args.first
22
+ def visit_Arel_Attributes_Attribute(o, collector)
24
23
  join_name = o.relation.table_alias || o.relation.name
25
- result = "#{quote_local_table_name join_name}.#{quote_column_name o.name}"
26
- args.last << result
24
+ collector << quote_local_table_name(join_name) << '.' << quote_column_name(o.name)
25
+ end
26
+
27
+ def visit_Arel_Nodes_HomogeneousIn(o, collector)
28
+ collector.preparable = false
29
+
30
+ collector << quote_local_table_name(o.table_name) << '.' << quote_column_name(o.column_name)
31
+
32
+ collector << if o.type == :in
33
+ ' IN ('
34
+ else
35
+ ' NOT IN ('
36
+ end
37
+
38
+ values = o.casted_values
39
+
40
+ if values.empty?
41
+ collector << @connection.quote(nil)
42
+ else
43
+ collector.add_binds(values, o.proc_for_binds, &bind_block)
44
+ end
45
+
46
+ collector << ')'
47
+ collector
27
48
  end
28
49
 
29
50
  # rubocop:enable Naming/MethodName
51
+ # rubocop:enable Naming/MethodParameterName
30
52
 
31
53
  def quote_local_table_name(name)
32
54
  return name if ::Arel::Nodes::SqlLiteral === name
@@ -13,7 +13,7 @@ module Switchman
13
13
  end
14
14
 
15
15
  def cache
16
- Switchman::Shard.current.database_server.cache_store
16
+ Switchman::Shard.current ? Switchman::Shard.current.database_server.cache_store : super
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.0.7'
4
+ VERSION = '3.0.10'
5
5
  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: 3.0.7
4
+ version: 3.0.10
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: 2022-02-23 00:00:00.000000000 Z
13
+ date: 2022-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord