From e8eb743ba679ccfe13e3cd15f140b539f1562340 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 1 Dec 2006 05:37:56 +0000 Subject: Replace the elaborate reloading connection checking scheme, just fix the Ruby-based MySQL adapter, ye? git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5656 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/abstract/connection_specification.rb | 8 -------- .../lib/active_record/connection_adapters/abstract_adapter.rb | 6 ------ .../lib/active_record/connection_adapters/sqlite_adapter.rb | 4 ---- activerecord/lib/active_record/vendor/mysql.rb | 10 ++++++++-- railties/lib/dispatcher.rb | 7 ++----- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index 31c288b932..ae59176fa3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -86,14 +86,6 @@ module ActiveRecord conn.disconnect! end end - - # Clears the cache which maps classes - def clear_reloadable_connections! - @@active_connections.each do |name, conn| - conn.disconnect! if conn.supports_reloading? - @@active_connections.delete(name) - end - end # Verify active connections. def verify_active_connections! #:nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 07e3182761..949b8f7951 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -79,12 +79,6 @@ module ActiveRecord @active = false end - # Returns true if its safe to reload the connection between requests for development mode. - # This is not the case for Ruby/MySQL and it's not necessary for any adapters except SQLite. - def supports_reloading? - false - end - # Lazily verify this connection, calling +active?+ only if it hasn't # been called for +timeout+ seconds. def verify!(timeout) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 341e546084..b0c86f51a5 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -102,10 +102,6 @@ module ActiveRecord true end - def supports_reloading? - true - end - def supports_count_distinct? #:nodoc: sqlite_version >= '3.2.6' end diff --git a/activerecord/lib/active_record/vendor/mysql.rb b/activerecord/lib/active_record/vendor/mysql.rb index 0d8cc2efd8..58ebed7d4f 100644 --- a/activerecord/lib/active_record/vendor/mysql.rb +++ b/activerecord/lib/active_record/vendor/mysql.rb @@ -1173,8 +1173,14 @@ class << Mysql def finalizer(net) proc { - net.clear - net.write Mysql::COM_QUIT.chr + begin + net.clear + net.write Mysql::COM_QUIT.chr + net.close + rescue Error => error + # Swallow lost connection errors if connection is already closed. + raise unless error.errno == Error::CR_SERVER_LOST + end } end diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 31eb5d2317..ce6f505895 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -62,7 +62,7 @@ class Dispatcher Class.remove_class(*Reloadable.reloadable_classes) end - ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) + ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord) end # Add a preparation callback. Preparation callbacks are run before every @@ -76,16 +76,13 @@ class Dispatcher def to_prepare(identifier = nil, &block) unless identifier.nil? callback = preparation_callbacks.detect { |ident, _| ident == identifier } - if callback # Already registered: update the existing callback callback[-1] = block return end end - preparation_callbacks << [identifier, block] - - return + nil end private -- cgit v1.2.3