From b0556ae4a65c7cad8671d938f0877c54e93d3723 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Mon, 5 Jun 2017 22:47:36 -0700 Subject: [PATCH 01/13] support query cache syncing --- fresh_connection.gemspec | 1 + .../abstract_connection_manager.rb | 2 +- lib/fresh_connection/connection_factory.rb | 6 +- lib/fresh_connection/connection_manager.rb | 38 ++++++++-- .../extend/ar_abstract_adapter.rb | 20 ++++- lib/fresh_connection/extend/ar_base.rb | 20 +++++ .../replica_connection_handler.rb | 18 +++++ test/ar_base/ar_abstract_adapter_test.rb | 76 +++++++++++++++++++ test/config/database_mysql2.yml | 2 + test/config/database_postgresql.yml | 2 + 10 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 test/ar_base/ar_abstract_adapter_test.rb diff --git a/fresh_connection.gemspec b/fresh_connection.gemspec index f4aa6d0..38724aa 100644 --- a/fresh_connection.gemspec +++ b/fresh_connection.gemspec @@ -33,4 +33,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-reporters" spec.add_development_dependency "benchmark-ips" + spec.add_development_dependency "pry-byebug" end diff --git a/lib/fresh_connection/abstract_connection_manager.rb b/lib/fresh_connection/abstract_connection_manager.rb index d0129f1..e95422d 100644 --- a/lib/fresh_connection/abstract_connection_manager.rb +++ b/lib/fresh_connection/abstract_connection_manager.rb @@ -12,7 +12,7 @@ def method_added(name) end end - attr_reader :replica_group + attr_reader :replica_group def initialize(replica_group = "replica") replica_group = "replica" if replica_group.to_s == "slave" diff --git a/lib/fresh_connection/connection_factory.rb b/lib/fresh_connection/connection_factory.rb index 95b57ba..6176708 100644 --- a/lib/fresh_connection/connection_factory.rb +++ b/lib/fresh_connection/connection_factory.rb @@ -11,8 +11,10 @@ def initialize(group, modify_spec = nil) @spec = nil end - def new_connection - ActiveRecord::Base.__send__(adapter_method, spec) + def new_connection(pool = nil) + ActiveRecord::Base.__send__(adapter_method, spec).tap do |conn| + conn.connection_pool = pool + end end private diff --git a/lib/fresh_connection/connection_manager.rb b/lib/fresh_connection/connection_manager.rb index 13715ac..e11e873 100644 --- a/lib/fresh_connection/connection_manager.rb +++ b/lib/fresh_connection/connection_manager.rb @@ -1,9 +1,13 @@ +require 'active_record' require 'concurrent' require 'fresh_connection/abstract_connection_manager' require 'fresh_connection/connection_factory' module FreshConnection class ConnectionManager < AbstractConnectionManager + + include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration + def initialize(*args) super @connections = Concurrent::Map.new @@ -11,23 +15,41 @@ def initialize(*args) def replica_connection @connections.fetch_or_store(current_thread_id) do |_| - connection_factory.new_connection + connection_factory.new_connection(self) end end def put_aside! - conn = @connections.delete(current_thread_id) - return unless conn - conn && conn.disconnect! rescue nil + if (conn = @connections.delete(current_thread_id)) + conn.disconnect! rescue nil + end end def clear_all_connections! - @connections.each_value do |conn| + for_all_connections do |conn| conn.disconnect! rescue nil end @connections.clear end + def clear_replica_query_caches! + for_all_connections do |conn| + conn.clear_query_cache + end + end + + def enable_query_cache! + for_all_connections do |conn| + conn.enable_query_cache! + end + end + + def disable_query_cache! + for_all_connections do |conn| + conn.disable_query_cache! + end + end + def recovery? return false if replica_connection.active? put_aside! @@ -36,6 +58,12 @@ def recovery? private + def for_all_connections + @connections.each_value do |connection| + yield(connection) + end + end + def connection_factory @connection_factory ||= ConnectionFactory.new(@replica_group) end diff --git a/lib/fresh_connection/extend/ar_abstract_adapter.rb b/lib/fresh_connection/extend/ar_abstract_adapter.rb index 183ee6f..458b2d5 100644 --- a/lib/fresh_connection/extend/ar_abstract_adapter.rb +++ b/lib/fresh_connection/extend/ar_abstract_adapter.rb @@ -1,8 +1,16 @@ +require 'pry-byebug' + module FreshConnection module Extend module ArAbstractAdapter def self.prepended(base) - base.send :attr_writer, :replica_group + base.send :attr_accessor, :replica_group + base.send :attr_accessor, :connection_pool + end + + def initialize(connection, logger = nil, config = {}) + super + @connection_pool = nil end def log(*args) @@ -12,9 +20,13 @@ def log(*args) # This is normally called only on master connections, so we need # to clear the replica connection caches, too. But, don't recurse. - #def clear_query_cache - # replica_connection.clear_query_cache unless replica_group - #end + def clear_query_cache + if FreshConnection::ReplicaConnectionHandler.replica_query_cache_sync + ActiveRecord::Base.clear_all_query_caches! unless replica_group + end + super + end + end end end diff --git a/lib/fresh_connection/extend/ar_base.rb b/lib/fresh_connection/extend/ar_base.rb index 4eab2cf..6918d80 100644 --- a/lib/fresh_connection/extend/ar_base.rb +++ b/lib/fresh_connection/extend/ar_base.rb @@ -29,6 +29,10 @@ def establish_fresh_connection(replica_group = "replica") replica_connection_handler.establish_connection(name, replica_group) end + def master_connection + superclass.connection + end + def replica_connection replica_connection_handler.connection(self) end @@ -53,6 +57,22 @@ def clear_all_slave_connections! clear_all_replica_connections! end + def clear_all_query_caches! + replica_connection_handler.clear_all_query_caches! + end + + def enable_replica_query_cache_sync! + FreshConnection::ReplicaConnectionHandler.enable_query_cache_sync! + end + + def disable_replica_query_cache_sync! + FreshConnection::ReplicaConnectionHandler.disable_query_cache_sync! + end + + def replica_query_cache_sync + FreshConnection::ReplicaConnectionHandler.replica_query_cache_sync + end + def master_db_only! @_fresh_connection_master_only = true end diff --git a/lib/fresh_connection/replica_connection_handler.rb b/lib/fresh_connection/replica_connection_handler.rb index 1ac7488..dc5763c 100644 --- a/lib/fresh_connection/replica_connection_handler.rb +++ b/lib/fresh_connection/replica_connection_handler.rb @@ -1,7 +1,19 @@ require 'concurrent' module FreshConnection + class ReplicaConnectionHandler + + cattr_accessor :replica_query_cache_sync + + def self.enable_query_cache_sync! + @@replica_query_cache_sync = true + end + + def self.disable_query_cache_sync! + @@replica_query_cache_sync = false + end + def initialize @replica_group_to_pool = Concurrent::Map.new @class_to_pool = Concurrent::Map.new @@ -26,6 +38,12 @@ def clear_all_connections! end end + def clear_all_query_caches! + all_connection_managers do |connection_manager| + connection_manager.clear_replica_query_caches! + end + end + def recovery?(klass) detect_connection_manager(klass).recovery? end diff --git a/test/ar_base/ar_abstract_adapter_test.rb b/test/ar_base/ar_abstract_adapter_test.rb new file mode 100644 index 0000000..879d365 --- /dev/null +++ b/test/ar_base/ar_abstract_adapter_test.rb @@ -0,0 +1,76 @@ +require "test_helper" +#require 'pry-byebug' + +class AbstractAdapterTest < Minitest::Test + + class Tel < ActiveRecord::Base + establish_fresh_connection :fake_replica + enable_replica_query_cache_sync! + + belongs_to :user + end + + def setup + ActiveRecord::Base.connection.clear_query_cache + end + + test "cache_query is incorrect after master update with replica cache syncing disabled" do + + Tel.cache do + + Tel.replica_connection.enable_query_cache! + Tel.disable_replica_query_cache_sync! + + tel = Tel.find(1) + assert_match(/master/ , tel.number) + rconn = Tel.replica_connection + mconn = Tel.master_connection + + refute rconn.query_cache.empty? + assert mconn.query_cache.empty? + + orig_number = tel.number + tel.number = tel.number.sub(/master/,'fake_replica') + tel.save! + assert mconn.query_cache.empty? + refute rconn.query_cache.empty? # the replica cache should still have some contents after an update + + tel2 = Tel.find(1) + refute_equal tel2.number, tel.number # the replica cache contents should be stale + + tel.number = orig_number + tel.save! + end + + end + + test "cache_query is correct after master update with replica cache syncing enabled" do + + Tel.cache do + + Tel.replica_connection.enable_query_cache! + Tel.enable_replica_query_cache_sync! + + tel = Tel.find(1) + assert_match(/master/ , tel.number) + rconn = Tel.replica_connection + mconn = Tel.master_connection + + refute rconn.query_cache.empty? # the replica cache should have some contents + assert mconn.query_cache.empty? # the master connection cache is always empty + + orig_number = tel.number + tel.number = tel.number.sub(/master/,'fake_replica') + tel.save! + + tel2 = Tel.find(1) + assert_equal tel2.number, tel.number # the replica should have pulled fresh, correct data + + tel.number = orig_number + tel.save! + end + + end + +end + diff --git a/test/config/database_mysql2.yml b/test/config/database_mysql2.yml index 71b7547..403f119 100644 --- a/test/config/database_mysql2.yml +++ b/test/config/database_mysql2.yml @@ -12,3 +12,5 @@ test: replica2: database: fresh_connection_test_replica2 + fake_replica: + database: fresh_connection_test_master diff --git a/test/config/database_postgresql.yml b/test/config/database_postgresql.yml index 72db19a..985a881 100644 --- a/test/config/database_postgresql.yml +++ b/test/config/database_postgresql.yml @@ -10,3 +10,5 @@ test: replica2: database: fresh_connection_test_replica2 + fake_replica: + database: fresh_connection_test_master From 05a44b8c49857434ba4829447ff7b75c29809a96 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Mon, 5 Jun 2017 23:12:41 -0700 Subject: [PATCH 02/13] bump version --- lib/fresh_connection/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 1ce17a6..60b1521 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.0.rc3" + VERSION = "2.3.0.rc4" end From a11677b5cdf9a1b713c539f350898e6d2d4d992f Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Mon, 5 Jun 2017 23:17:04 -0700 Subject: [PATCH 03/13] bump version --- lib/fresh_connection/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 60b1521..ee09f59 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.0.rc4" + VERSION = "2.3.1.rc1" end From c294ceef07bb21ffb5ddba31cc2fc79cb7f88374 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 09:18:25 -0700 Subject: [PATCH 04/13] add support for Rails 4xx --- gemfiles/rails42.gemfile | 2 +- gemfiles/rails50.gemfile | 2 +- lib/fresh_connection/connection_manager.rb | 8 +++++++- lib/fresh_connection/version.rb | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gemfiles/rails42.gemfile b/gemfiles/rails42.gemfile index 196081f..6b94e28 100644 --- a/gemfiles/rails42.gemfile +++ b/gemfiles/rails42.gemfile @@ -6,4 +6,4 @@ gem "activerecord", "~> 4.2.0" gem "activesupport", "~> 4.2.0" gem "mysql2", "~> 0.3.13" -gemspec :path => "../" +gemspec path: "../" diff --git a/gemfiles/rails50.gemfile b/gemfiles/rails50.gemfile index 2004404..3ab0374 100644 --- a/gemfiles/rails50.gemfile +++ b/gemfiles/rails50.gemfile @@ -6,4 +6,4 @@ gem "activerecord", "~> 5.0.0" gem "activesupport", "~> 5.0.0" gem "mysql2", ">= 0.3.18", "< 0.5" -gemspec :path => "../" +gemspec path: "../" diff --git a/lib/fresh_connection/connection_manager.rb b/lib/fresh_connection/connection_manager.rb index e11e873..1b036f5 100644 --- a/lib/fresh_connection/connection_manager.rb +++ b/lib/fresh_connection/connection_manager.rb @@ -6,13 +6,19 @@ module FreshConnection class ConnectionManager < AbstractConnectionManager - include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration + if ActiveRecord::VERSION::MAJOR == 5 + include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration + end def initialize(*args) super @connections = Concurrent::Map.new + if ActiveRecord::VERSION::MAJOR == 4 + @query_cache_enabled = Concurrent::Map.new { false } + end end + def replica_connection @connections.fetch_or_store(current_thread_id) do |_| connection_factory.new_connection(self) diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index ee09f59..c7fc009 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc1" + VERSION = "2.3.1.rc2" end From 4d1e7f06c240cbeae76b56fad43d29c282cb4c7f Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 10:30:20 -0700 Subject: [PATCH 05/13] slight refactor to avoid spurious recursion --- .../abstract_connection_manager.rb | 4 ++++ lib/fresh_connection/connection_manager.rb | 10 +++++----- .../extend/ar_abstract_adapter.rb | 16 +++++++++++++++- lib/fresh_connection/extend/ar_base.rb | 4 ++-- .../replica_connection_handler.rb | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/fresh_connection/abstract_connection_manager.rb b/lib/fresh_connection/abstract_connection_manager.rb index e95422d..ed03891 100644 --- a/lib/fresh_connection/abstract_connection_manager.rb +++ b/lib/fresh_connection/abstract_connection_manager.rb @@ -36,6 +36,10 @@ def clear_all_connections! end undef_method :clear_all_connections! + def clear_replica_query_caches! + end + undef_method :clear_replica_query_caches! + def put_aside! end undef_method :put_aside! diff --git a/lib/fresh_connection/connection_manager.rb b/lib/fresh_connection/connection_manager.rb index 1b036f5..333f911 100644 --- a/lib/fresh_connection/connection_manager.rb +++ b/lib/fresh_connection/connection_manager.rb @@ -32,26 +32,26 @@ def put_aside! end def clear_all_connections! - for_all_connections do |conn| + for_all_replica_connections do |conn| conn.disconnect! rescue nil end @connections.clear end def clear_replica_query_caches! - for_all_connections do |conn| + for_all_replica_connections do |conn| conn.clear_query_cache end end def enable_query_cache! - for_all_connections do |conn| + for_all_replica_connections do |conn| conn.enable_query_cache! end end def disable_query_cache! - for_all_connections do |conn| + for_all_replica_connections do |conn| conn.disable_query_cache! end end @@ -64,7 +64,7 @@ def recovery? private - def for_all_connections + def for_all_replica_connections @connections.each_value do |connection| yield(connection) end diff --git a/lib/fresh_connection/extend/ar_abstract_adapter.rb b/lib/fresh_connection/extend/ar_abstract_adapter.rb index 458b2d5..94cbf26 100644 --- a/lib/fresh_connection/extend/ar_abstract_adapter.rb +++ b/lib/fresh_connection/extend/ar_abstract_adapter.rb @@ -22,7 +22,21 @@ def log(*args) # to clear the replica connection caches, too. But, don't recurse. def clear_query_cache if FreshConnection::ReplicaConnectionHandler.replica_query_cache_sync - ActiveRecord::Base.clear_all_query_caches! unless replica_group + + # This call is interesting. Here, in the FreshConnection + # extension to the AR AbstractAdapter, we are either on a :master + # connection or a :replica connection. Unfortunately, there is no direct + # linkage between them. So, from a :master connection, we don't know + # which :replica connection pool to use, or even which :replica connection + # manager to use, because those are associated with AR objects, not + # AR adapters. + + # So, we need to "cross over" from the master connection side to the + # replica connection side, via a top-level AR::Base call, but we need + # to avoid accidental recursions, too. The "replica_group" test + # should be non-nil for replica connections. + + ActiveRecord::Base.clear_replica_query_caches! unless replica_group end super end diff --git a/lib/fresh_connection/extend/ar_base.rb b/lib/fresh_connection/extend/ar_base.rb index 6918d80..e8d7667 100644 --- a/lib/fresh_connection/extend/ar_base.rb +++ b/lib/fresh_connection/extend/ar_base.rb @@ -57,8 +57,8 @@ def clear_all_slave_connections! clear_all_replica_connections! end - def clear_all_query_caches! - replica_connection_handler.clear_all_query_caches! + def clear_replica_query_caches! + replica_connection_handler.clear_replica_query_caches! end def enable_replica_query_cache_sync! diff --git a/lib/fresh_connection/replica_connection_handler.rb b/lib/fresh_connection/replica_connection_handler.rb index dc5763c..b33e18d 100644 --- a/lib/fresh_connection/replica_connection_handler.rb +++ b/lib/fresh_connection/replica_connection_handler.rb @@ -38,7 +38,7 @@ def clear_all_connections! end end - def clear_all_query_caches! + def clear_replica_query_caches! all_connection_managers do |connection_manager| connection_manager.clear_replica_query_caches! end From 0a9d44fa25b0c8b452406b33ee8d98f77d1be566 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 11:46:48 -0700 Subject: [PATCH 06/13] avoid reference to undefined constants in Rails4 --- lib/fresh_connection/connection_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/connection_manager.rb b/lib/fresh_connection/connection_manager.rb index 333f911..fb39bd6 100644 --- a/lib/fresh_connection/connection_manager.rb +++ b/lib/fresh_connection/connection_manager.rb @@ -7,7 +7,7 @@ module FreshConnection class ConnectionManager < AbstractConnectionManager if ActiveRecord::VERSION::MAJOR == 5 - include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration + eval "include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration" end def initialize(*args) From 6a78470d3d09acc10f320296e4c9d9dfb358ef9d Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 11:47:53 -0700 Subject: [PATCH 07/13] avoid references to undefined constants in Rails4 --- lib/fresh_connection/connection_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/connection_manager.rb b/lib/fresh_connection/connection_manager.rb index 333f911..829ba26 100644 --- a/lib/fresh_connection/connection_manager.rb +++ b/lib/fresh_connection/connection_manager.rb @@ -7,7 +7,7 @@ module FreshConnection class ConnectionManager < AbstractConnectionManager if ActiveRecord::VERSION::MAJOR == 5 - include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration + eval 'include ::ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration' end def initialize(*args) From a7d7fe9d0f832adacdcbd58c8a600da47e9124c4 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 11:48:24 -0700 Subject: [PATCH 08/13] bump version --- lib/fresh_connection/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index c7fc009..058899e 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc2" + VERSION = "2.3.1.rc3" end From 612be47edb6231e555114076db8f6dd42181b7fc Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 14:04:56 -0700 Subject: [PATCH 09/13] remove non-production gem & bump version --- fresh_connection.gemspec | 2 +- lib/fresh_connection/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fresh_connection.gemspec b/fresh_connection.gemspec index 38724aa..bbcd419 100644 --- a/fresh_connection.gemspec +++ b/fresh_connection.gemspec @@ -33,5 +33,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-reporters" spec.add_development_dependency "benchmark-ips" - spec.add_development_dependency "pry-byebug" + #spec.add_development_dependency "pry-byebug" # debugging only end diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 058899e..63ece90 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc3" + VERSION = "2.3.1.rc4" end From d0840b1a6696e2f585f54d3dfd29b571b271de5d Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 14:06:01 -0700 Subject: [PATCH 10/13] remove non-production gem & bump version --- fresh_connection.gemspec | 2 +- lib/fresh_connection/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fresh_connection.gemspec b/fresh_connection.gemspec index 38724aa..bbcd419 100644 --- a/fresh_connection.gemspec +++ b/fresh_connection.gemspec @@ -33,5 +33,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-reporters" spec.add_development_dependency "benchmark-ips" - spec.add_development_dependency "pry-byebug" + #spec.add_development_dependency "pry-byebug" # debugging only end diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 058899e..63ece90 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc3" + VERSION = "2.3.1.rc4" end From a26e3dcbbea001896efe3396319228b6818c79cc Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 14:06:01 -0700 Subject: [PATCH 11/13] remove non-production gem & bump version --- fresh_connection.gemspec | 2 +- lib/fresh_connection/extend/ar_abstract_adapter.rb | 2 -- lib/fresh_connection/version.rb | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fresh_connection.gemspec b/fresh_connection.gemspec index 38724aa..bbcd419 100644 --- a/fresh_connection.gemspec +++ b/fresh_connection.gemspec @@ -33,5 +33,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-reporters" spec.add_development_dependency "benchmark-ips" - spec.add_development_dependency "pry-byebug" + #spec.add_development_dependency "pry-byebug" # debugging only end diff --git a/lib/fresh_connection/extend/ar_abstract_adapter.rb b/lib/fresh_connection/extend/ar_abstract_adapter.rb index 94cbf26..05bda81 100644 --- a/lib/fresh_connection/extend/ar_abstract_adapter.rb +++ b/lib/fresh_connection/extend/ar_abstract_adapter.rb @@ -1,5 +1,3 @@ -require 'pry-byebug' - module FreshConnection module Extend module ArAbstractAdapter diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 058899e..63ece90 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc3" + VERSION = "2.3.1.rc4" end From bf670f6ff350d17c952b04b3fd00196498d3bc30 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Tue, 6 Jun 2017 14:23:29 -0700 Subject: [PATCH 12/13] new release --- lib/fresh_connection/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index 63ece90..d4e7809 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc4" + VERSION = "2.3.1.rc5" end From ef22b25a3d7b3f014689adc2d2bcc159659ab499 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Mon, 12 Jun 2017 16:45:02 -0700 Subject: [PATCH 13/13] try harder to avoid recursing on master --- lib/fresh_connection/extend/ar_abstract_adapter.rb | 4 +++- lib/fresh_connection/version.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fresh_connection/extend/ar_abstract_adapter.rb b/lib/fresh_connection/extend/ar_abstract_adapter.rb index 27e2a21..863aee5 100644 --- a/lib/fresh_connection/extend/ar_abstract_adapter.rb +++ b/lib/fresh_connection/extend/ar_abstract_adapter.rb @@ -34,7 +34,9 @@ def clear_query_cache # to avoid accidental recursions, too. The "replica_group" test # should be non-nil for replica connections. - ActiveRecord::Base.clear_replica_query_caches! unless replica_group + if replica_group.nil? || replica_group == :master + ActiveRecord::Base.clear_replica_query_caches! + end end super end diff --git a/lib/fresh_connection/version.rb b/lib/fresh_connection/version.rb index d4e7809..e8e3948 100644 --- a/lib/fresh_connection/version.rb +++ b/lib/fresh_connection/version.rb @@ -1,4 +1,4 @@ module FreshConnection - VERSION = "2.3.1.rc5" + VERSION = "2.3.1.rc6" end