Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
If only life was that simple (it didnt help)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5658 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Dec 1, 2006
1 parent e8eb743 commit 2e2bf2d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
Expand Up @@ -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:
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -102,6 +102,10 @@ def supports_migrations? #:nodoc:
true
end

def supports_reloading?
true
end

def supports_count_distinct? #:nodoc:
sqlite_version >= '3.2.6'
end
Expand Down
10 changes: 2 additions & 8 deletions activerecord/lib/active_record/vendor/mysql.rb
Expand Up @@ -1173,14 +1173,8 @@ def real_connect(*args)

def finalizer(net)
proc {
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
net.clear
net.write Mysql::COM_QUIT.chr
}
end

Expand Down
7 changes: 5 additions & 2 deletions railties/lib/dispatcher.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2e2bf2d

Please sign in to comment.