Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only reload connections in development mode that supports (and requir…

…es that) -- in other words, only do it for SQLite (closes #6687, #6700) [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 205ae50d3fb04082e705bb09fa011a06ccd7f4eb 1 parent 5b8bfc4
David Heinemeier Hansson dhh authored
8 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
View
@@ -86,6 +86,14 @@ def clear_active_connections!
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:
6 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
View
@@ -79,6 +79,12 @@ def disconnect!
@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)
4 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
View
@@ -101,6 +101,10 @@ def adapter_name #:nodoc:
def supports_migrations? #:nodoc:
true
end
+
+ def supports_reloading?
+ true
+ end
def supports_count_distinct? #:nodoc:
false
7 railties/lib/dispatcher.rb
View
@@ -62,7 +62,7 @@ def reset_application!
Class.remove_class(*Reloadable.reloadable_classes)
end
- ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord)
+ ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
# Add a preparation callback. Preparation callbacks are run before every
@@ -76,13 +76,16 @@ def reset_application!
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]
- nil
+
+ return
end
private
Please sign in to comment.
Something went wrong with that request. Please try again.