replica_pools 2.1.1 → 2.2.1

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
- SHA1:
3
- metadata.gz: ccf84c0499a86c7e36948d178c8fb150fc71003b
4
- data.tar.gz: 93bc95a40cd6a411ea255bc3fc94e2e8860add71
2
+ SHA256:
3
+ metadata.gz: b9a32096014e9f2cd137adb7c8fe226173f40d9dea893a319c0dab24cbdf8371
4
+ data.tar.gz: da62952df8213322963f8b8ce0c5da9ed8efe381c2348801794ec0ef0b6d294a
5
5
  SHA512:
6
- metadata.gz: 947621a358c1034cc8a45b70e1f56d1a58126552c700ec18f3e636cfbd80f44eeb9c3288ad3cc78f142a52a3a9df7668cc746f14ba71cd242596998d96bd3182
7
- data.tar.gz: 4cc0aab455a96d11d2c56fb17e3af40ec8ae33502bf1a70064c71c9e26a043f41ea7ab47937923735408827bb358cb766d5e8dadedeefe57b1206df8ba44e302
6
+ metadata.gz: 7f2d2abc5f7badb102c8116213b306d35336f6d54c651a74d6fcaa0e37c53c5282c46fbc643984ffde43f5e54d868051c38590372b8af4329741da1247b68128
7
+ data.tar.gz: 51c4514ec6e0fa79ea2e6b128fd4d6d3866916d65d89ec743f49621678a5997c0dd3bc0bfe78a25acd72c39d61c5f13523a9f84a9160259966f9408f9c56b109
data/README.md CHANGED
@@ -186,11 +186,15 @@ Then you can run tests with:
186
186
  $ bundle exec rake spec
187
187
  ```
188
188
 
189
+ ## Releasing a New Version
190
+
191
+ First bump the version as appropriate in `lib/replica_pools/version.rb` and then run `bundle exec rake release`. This will push git tags to github and package and push the gem to rubygems.org.
192
+
189
193
  ## Authors
190
194
 
191
195
  Author: Dan Drabik, Lance Ivy
192
196
 
193
- Copyright (c) 2012-2018, Kickstarter
197
+ Copyright (c) 2012-2021, Kickstarter
194
198
 
195
199
  Released under the MIT license
196
200
 
@@ -21,15 +21,15 @@ module ReplicaPools
21
21
  :select_rows, :select, :verify!, :raw_connection, :active?, :reconnect!,
22
22
  :disconnect!, :reset_runtime, :log
23
23
  ]
24
- elsif ActiveRecord::VERSION::MAJOR == 5
24
+ elsif [5, 6].include?(ActiveRecord::VERSION::MAJOR)
25
25
  [
26
26
  :select_all, :select_one, :select_value, :select_values,
27
27
  :select_rows, :select, :select_prepared, :verify!, :raw_connection,
28
28
  :active?, :reconnect!, :disconnect!, :reset_runtime, :log,
29
29
  :lookup_cast_type_from_column, :sanitize_limit,
30
- :combine_bind_parameters, :quote_table_name, :quote, :quote_column_names, :quote_table_names,
30
+ :combine_bind_parameters, :quote_table_name, :quote, :quote_column_names, :quote_table_names, :table_alias_for,
31
31
  :case_sensitive_comparison, :case_insensitive_comparison,
32
- :schema_cache, :cacheable_query, :prepared_statements, :clear_cache!
32
+ :schema_cache, :cacheable_query, :prepared_statements, :clear_cache!, :column_name_for_operation
33
33
  ]
34
34
  else
35
35
  warn "Unsupported ActiveRecord version #{ActiveRecord.version}. Please whitelist the safe methods."
@@ -27,12 +27,22 @@ module ReplicaPools
27
27
 
28
28
  # finds valid pool configs
29
29
  def pool_configurations
30
- ActiveRecord::Base.configurations.map do |name, config|
30
+ config_hash.map do |name, config|
31
31
  next unless name.to_s =~ /#{ReplicaPools.config.environment}_pool_(.*)_name_(.*)/
32
32
  [name, $1, $2]
33
33
  end.compact
34
34
  end
35
35
 
36
+ def config_hash
37
+ if ActiveRecord::VERSION::MAJOR >= 6
38
+ # in Rails >= 6, `configurations` is an instance of ActiveRecord::DatabaseConfigurations
39
+ ActiveRecord::Base.configurations.to_h
40
+ else
41
+ # in Rails < 6, it's just a hash
42
+ ActiveRecord::Base.configurations
43
+ end
44
+ end
45
+
36
46
  # generates a unique ActiveRecord::Base subclass for a single replica
37
47
  def connection_class(pool_name, replica_name, connection_name)
38
48
  class_name = "#{pool_name.camelize}#{replica_name.camelize}"
@@ -24,6 +24,8 @@ module ReplicaPools
24
24
  # there may be more args for Rails 5.0+, but we only care about arel, name, and binds for caching.
25
25
  relation, name, raw_binds = args
26
26
 
27
+ # Rails 6.2 breaks this method as locked? is no longer available
28
+ # https://github.com/kickstarter/replica_pools/issues/26
27
29
  if !query_cache_enabled || locked?(relation)
28
30
  return route_to(current, :select_all, *args)
29
31
  end
@@ -32,7 +34,7 @@ module ReplicaPools
32
34
  if raw_binds.blank? && relation.is_a?(ActiveRecord::Relation)
33
35
  arel, binds = relation.arel, relation.bind_values
34
36
  else
35
- arel, binds = relation, raw_binds
37
+ arel, binds = relation, Array(raw_binds)
36
38
  end
37
39
 
38
40
  sql = to_sql(arel, binds)
@@ -1,3 +1,3 @@
1
1
  module ReplicaPools
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'rack'
2
2
  require_relative 'spec_helper'
3
+ require_relative 'config/test_model'
3
4
 
4
5
  describe ReplicaPools::QueryCache do
5
6
  before(:each) do
@@ -103,4 +104,16 @@ describe ReplicaPools::QueryCache do
103
104
  end
104
105
  end
105
106
  end
107
+
108
+ describe '.pluck regression test' do
109
+ it 'should work with query caching' do
110
+ TestModel.connection.enable_query_cache!
111
+ expect(TestModel.pluck(:id).count).to eql TestModel.all.count
112
+ end
113
+
114
+ it 'should work if query cache is not enabled' do
115
+ TestModel.connection.disable_query_cache!
116
+ expect(TestModel.pluck(:id).count).to eql TestModel.all.count
117
+ end
118
+ end
106
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replica_pools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Drabik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-17 00:00:00.000000000 Z
12
+ date: 2021-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  description: Connection proxy for ActiveRecord for leader / replica setups.
99
113
  email: dan@kickstarter.com
100
114
  executables: []
@@ -138,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
152
  - !ruby/object:Gem::Version
139
153
  version: '1.2'
140
154
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.4.5.1
155
+ rubygems_version: 3.0.3
143
156
  signing_key:
144
157
  specification_version: 4
145
158
  summary: Connection proxy for ActiveRecord for leader / replica setups.