active_record_shards 3.9.2 → 3.10.0

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: 81a720c8a58e8f5108776bb9521d96a0655b4716
4
- data.tar.gz: 2766cade5b7e607dc1f7bc941ba006f30f85cdc1
3
+ metadata.gz: 4910854dd97e92f0aab3a997b23c4f830d98e66f
4
+ data.tar.gz: df78f89f7245ab25bd3ca40c06990ceb929b66f9
5
5
  SHA512:
6
- metadata.gz: bb3cbaf2517378f2bacb72dc2c2b9712c41e17d34831db3dab1db29510e1ca7216730e6b7d56538610495a8efe018ebc9ab1693e72947c934a638391bc67b549
7
- data.tar.gz: a56dc45cc5f35cd291e10055463c4c33e30d8c99c4bd21a23f493ccfa40c74f4a8e0cb2b06f511b9bda4678c3a82871a55808320b6c0a7d049bd5b624e68efe8
6
+ metadata.gz: b25b5bd49ed22d0ca64d951b4384533711c0ee6451bd881fd6756786f97b3747ed10392756b1161460a0dc54f44a68c06847cb62f7e1387f568402405227411e
7
+ data.tar.gz: e29b7d4237ed37008edc25450b75bc620c3f10f50855ce7403334098be94b91a127297969c9bd4d6415f3ba106d626d9252fe39fc9ce94452a4e774b9d6a3e5c
@@ -27,11 +27,11 @@ ActiveRecord::Associations::CollectionProxy.include(ActiveRecordShards::Associat
27
27
 
28
28
  case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
29
29
  when '3.2'
30
- require 'active_record_shards-3-2'
30
+ require 'active_record_shards/patches-3-2'
31
31
  when '4.2'
32
- require 'active_record_shards-4-2'
32
+ require 'active_record_shards/patches-4-2'
33
33
  when '5.0', '5.1'
34
- require 'active_record_shards-5-0'
34
+ require 'active_record_shards/patches-5-0'
35
35
  else
36
36
  raise "ActiveRecordShards is not compatible with #{ActiveRecord::VERSION::STRING}"
37
37
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  ActiveRecord::ConnectionAdapters::ConnectionHandler.class_eval do
3
+ remove_method :retrieve_connection_pool
3
4
  if ActiveRecord::VERSION::MAJOR >= 4
4
5
  def retrieve_connection_pool(klass)
5
6
  class_to_pool[klass.connection_pool_name] ||= pool_for(klass)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
- ActiveRecord::Base.class_eval do
3
- def self.establish_connection(spec = ENV["DATABASE_URL"])
2
+ class << ActiveRecord::Base
3
+ remove_method :establish_connection unless ActiveRecord::VERSION::MAJOR == 4
4
+ def establish_connection(spec = ENV["DATABASE_URL"])
4
5
  if ActiveRecord::VERSION::MAJOR >= 4
5
6
  spec ||= ActiveRecord::ConnectionHandling::DEFAULT_ENV.call
6
7
  spec = spec.to_sym if spec.is_a?(String)
@@ -95,24 +95,25 @@ module ActiveRecordShards
95
95
  alias_method :with_slave_if, :on_slave_if
96
96
  alias_method :with_slave_unless, :on_slave_unless
97
97
 
98
- def on_cx_switch_block(which, options = {}, &block)
98
+ def on_cx_switch_block(which, force: false, construct_ro_scope: nil, &block)
99
99
  @disallow_slave ||= 0
100
+ @disallow_slave += 1 if which == :master
101
+
102
+ switch_to_slave = force || @disallow_slave.zero?
100
103
  old_options = current_shard_selection.options
101
- switch_to_slave = (which == :slave && @disallow_slave.zero?)
102
- switch_connection(slave: switch_to_slave)
103
104
 
104
- @disallow_slave += 1 if which == :master
105
+ switch_connection(slave: switch_to_slave)
105
106
 
106
107
  # we avoid_readonly_scope to prevent some stack overflow problems, like when
107
108
  # .columns calls .with_scope which calls .columns and onward, endlessly.
108
- if self == ActiveRecord::Base || !switch_to_slave || options[:construct_ro_scope] == false
109
+ if self == ActiveRecord::Base || !switch_to_slave || construct_ro_scope == false
109
110
  yield
110
111
  else
111
112
  readonly.scoping(&block)
112
113
  end
113
114
  ensure
114
115
  @disallow_slave -= 1 if which == :master
115
- switch_connection(old_options)
116
+ switch_connection(old_options) if old_options
116
117
  end
117
118
 
118
119
  def supports_sharding?
@@ -25,27 +25,29 @@ module ActiveRecordShards
25
25
  RUBY
26
26
  end
27
27
 
28
- def columns_with_default_slave(*args, &block)
29
- read_columns_from =
30
- if on_slave_by_default? && !Thread.current[:_active_record_shards_slave_off]
31
- :slave
32
- else
33
- :master
34
- end
35
-
36
- on_cx_switch_block(read_columns_from, construct_ro_scope: false) { columns_without_default_slave(*args, &block) }
28
+ def columns_with_force_slave(*args, &block)
29
+ on_cx_switch_block(:slave, construct_ro_scope: false, force: true) do
30
+ columns_without_force_slave(*args, &block)
31
+ end
37
32
  end
38
33
 
39
- def transaction_with_slave_off(*args, &block)
40
- if on_slave_by_default?
41
- old_val = Thread.current[:_active_record_shards_slave_off]
42
- Thread.current[:_active_record_shards_slave_off] = true
34
+ def table_exists_with_force_slave?(*args, &block)
35
+ on_cx_switch_block(:slave, construct_ro_scope: false, force: true) do
36
+ table_exists_without_force_slave?(*args, &block)
43
37
  end
38
+ end
44
39
 
45
- transaction_without_slave_off(*args, &block)
46
- ensure
40
+ def transaction_with_slave_off(*args, &block)
47
41
  if on_slave_by_default?
48
- Thread.current[:_active_record_shards_slave_off] = old_val
42
+ begin
43
+ old_val = Thread.current[:_active_record_shards_slave_off]
44
+ Thread.current[:_active_record_shards_slave_off] = true
45
+ transaction_without_slave_off(*args, &block)
46
+ ensure
47
+ Thread.current[:_active_record_shards_slave_off] = old_val
48
+ end
49
+ else
50
+ transaction_without_slave_off(*args, &block)
49
51
  end
50
52
  end
51
53
 
@@ -60,7 +62,7 @@ module ActiveRecordShards
60
62
  end
61
63
  end
62
64
 
63
- CLASS_SLAVE_METHODS = [:find_by_sql, :count_by_sql, :calculate, :find_one, :find_some, :find_every, :exists?, :table_exists?].freeze
65
+ CLASS_SLAVE_METHODS = [:find_by_sql, :count_by_sql, :calculate, :find_one, :find_some, :find_every, :exists?].freeze
64
66
 
65
67
  def self.extended(base)
66
68
  CLASS_SLAVE_METHODS.each { |m| ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(true, base, m) }
@@ -72,8 +74,11 @@ module ActiveRecordShards
72
74
  alias_method :reload, :reload_with_slave_off
73
75
 
74
76
  class << self
75
- alias_method :columns_without_default_slave, :columns
76
- alias_method :columns, :columns_with_default_slave
77
+ alias_method :columns_without_force_slave, :columns
78
+ alias_method :columns, :columns_with_force_slave
79
+
80
+ alias_method :table_exists_without_force_slave?, :table_exists?
81
+ alias_method :table_exists?, :table_exists_with_force_slave?
77
82
 
78
83
  alias_method :transaction_without_slave_off, :transaction
79
84
  alias_method :transaction, :transaction_with_slave_off
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.2
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-16 00:00:00.000000000 Z
13
+ date: 2017-09-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.48.1
117
+ version: 0.49.1
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.48.1
124
+ version: 0.49.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: minitest
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -188,9 +188,6 @@ extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
190
190
  - README.md
191
- - lib/active_record_shards-3-2.rb
192
- - lib/active_record_shards-4-2.rb
193
- - lib/active_record_shards-5-0.rb
194
191
  - lib/active_record_shards.rb
195
192
  - lib/active_record_shards/association_collection_connection_selection.rb
196
193
  - lib/active_record_shards/configuration_parser.rb
@@ -204,6 +201,9 @@ files:
204
201
  - lib/active_record_shards/default_slave_patches.rb
205
202
  - lib/active_record_shards/migration.rb
206
203
  - lib/active_record_shards/model.rb
204
+ - lib/active_record_shards/patches-3-2.rb
205
+ - lib/active_record_shards/patches-4-2.rb
206
+ - lib/active_record_shards/patches-5-0.rb
207
207
  - lib/active_record_shards/schema_dumper_extension.rb
208
208
  - lib/active_record_shards/shard_selection.rb
209
209
  - lib/active_record_shards/shard_support.rb