switchman 3.0.10 → 3.0.13

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
  SHA256:
3
- metadata.gz: e0148847d4a814e96ae663f5e2576e52a5feb9709a0b4ca7edf531884404e982
4
- data.tar.gz: df40d39aed43999ba851a99b74808704c99f536ef352194734a66b912c260564
3
+ metadata.gz: eb102ddffa5ff2319a8e73b4d62ff8b3ff18fe2e9905c9ecb03c4aa20fda4bd7
4
+ data.tar.gz: 941b024d4e92811e51bf53dedba0039aaea52c169398d0b50ecc7da6bc0aefbb
5
5
  SHA512:
6
- metadata.gz: 04e37250e9480e5c1d4683259c2cf5380e7da23bf44d890550920a0446a1dd3dfc1f371b294ccea6d25a3cd54b8605d8a1277613cba953e5b3d23325580d2fd2
7
- data.tar.gz: c8b4d479438201645fd5fab3997258e7e7e141680d2470ed2accef6922f32b664c9349e18b72b07e9a0fcf1366b47043deaf002feeadd3517138356a213010e9
6
+ metadata.gz: ea2c591ba32875d6cce5016c285fc3398e2bb491a7631ee5c900f3033c008292a38fd51c77d6a2b9abb00996963e8d8b0a61ca43c44a468025750a5aacd459be
7
+ data.tar.gz: e7e3f2b2ee7551e38f5d2d41b66eee7fb335c630ed1096598e25a1d09af506dfcbe63920de25828ce842c4b83c55a4abc70221e5c5a2fdc2e7f64b3fe181b50a
@@ -68,6 +68,9 @@ module Switchman
68
68
 
69
69
  initializer 'switchman.extend_ar', before: 'active_record.initialize_database' do
70
70
  ::ActiveSupport.on_load(:active_record) do
71
+ # Switchman requires postgres, so just always load the pg adapter
72
+ require 'active_record/connection_adapters/postgresql_adapter'
73
+
71
74
  require 'switchman/active_record/abstract_adapter'
72
75
  require 'switchman/active_record/association'
73
76
  require 'switchman/active_record/attribute_methods'
@@ -81,6 +84,7 @@ module Switchman
81
84
  require 'switchman/active_record/migration'
82
85
  require 'switchman/active_record/model_schema'
83
86
  require 'switchman/active_record/persistence'
87
+ require 'switchman/active_record/postgresql_adapter'
84
88
  require 'switchman/active_record/predicate_builder'
85
89
  require 'switchman/active_record/query_cache'
86
90
  require 'switchman/active_record/query_methods'
@@ -128,6 +132,7 @@ module Switchman
128
132
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::AbstractAdapter)
129
133
  ::ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ActiveRecord::ConnectionPool)
130
134
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecord::QueryCache)
135
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(ActiveRecord::PostgreSQLAdapter)
131
136
 
132
137
  ::ActiveRecord::DatabaseConfigurations.prepend(ActiveRecord::DatabaseConfigurations)
133
138
  ::ActiveRecord::DatabaseConfigurations::DatabaseConfig.prepend(ActiveRecord::DatabaseConfigurations::DatabaseConfig)
@@ -180,11 +185,6 @@ module Switchman
180
185
  require 'switchman/active_record/table_definition'
181
186
  ::ActiveRecord::ConnectionAdapters::TableDefinition.prepend(ActiveRecord::TableDefinition)
182
187
 
183
- if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
184
- require 'switchman/active_record/postgresql_adapter'
185
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(ActiveRecord::PostgreSQLAdapter)
186
- end
187
-
188
188
  Shard.send(:initialize_sharding)
189
189
  end
190
190
  end
@@ -3,20 +3,22 @@
3
3
  module Switchman
4
4
  module StandardError
5
5
  def initialize(*args)
6
- # Shard.current can throw this when switchman isn't working right; if we try to
7
- # do our stuff here, it'll cause a SystemStackError, which is a pain to deal with
8
- if is_a?(::ActiveRecord::ConnectionNotEstablished)
9
- super
10
- return
11
- end
6
+ super
7
+ # These seem to get themselves into a bad state if we try to lookup shards while processing
8
+ return if is_a?(IO::EAGAINWaitReadable)
9
+ return if Thread.current[:switchman_error_handler]
12
10
 
13
11
  begin
14
- @active_shards = Shard.active_shards if defined?(Shard)
15
- rescue ::ActiveRecord::ConnectionNotEstablished
16
- # If we hit an error really early in boot, activerecord may not be initialized yet
17
- end
12
+ Thread.current[:switchman_error_handler] = true
18
13
 
19
- super
14
+ begin
15
+ @active_shards = Shard.active_shards if defined?(Shard)
16
+ rescue
17
+ # If we hit an error really early in boot, activerecord may not be initialized yet
18
+ end
19
+ ensure
20
+ Thread.current[:switchman_error_handler] = nil
21
+ end
20
22
  end
21
23
 
22
24
  def current_shard(klass = ::ActiveRecord::Base)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.0.10'
4
+ VERSION = '3.0.13'
5
5
  end
@@ -35,9 +35,9 @@ module Switchman
35
35
 
36
36
  scope = base_scope.order(::Arel.sql('database_server_id IS NOT NULL, database_server_id, id'))
37
37
  if servers != DatabaseServer.all
38
- conditions = ['database_server_id IN (?)', servers.map(&:id)]
39
- conditions.first << ' OR database_server_id IS NULL' if servers.include?(Shard.default.database_server)
40
- scope = scope.where(conditions)
38
+ database_server_ids = servers.map(&:id)
39
+ database_server_ids << nil if servers.include?(Shard.default.database_server)
40
+ scope = scope.where(database_server_id: database_server_ids)
41
41
  end
42
42
 
43
43
  scope = shard_scope(scope, shard) if shard
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.10
4
+ version: 3.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  - James Williams
9
9
  - Jacob Fugal
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-21 00:00:00.000000000 Z
13
+ date: 2022-03-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -300,7 +300,7 @@ licenses:
300
300
  - MIT
301
301
  metadata:
302
302
  rubygems_mfa_required: 'true'
303
- post_install_message:
303
+ post_install_message:
304
304
  rdoc_options: []
305
305
  require_paths:
306
306
  - lib
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
316
  version: '0'
317
317
  requirements: []
318
318
  rubygems_version: 3.1.4
319
- signing_key:
319
+ signing_key:
320
320
  specification_version: 4
321
321
  summary: Rails sharding magic
322
322
  test_files: []