diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-27 21:37:30 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-27 21:37:30 +0000 |
commit | 3cfea287baa596833bd5e8bda5e12fd03250008f (patch) | |
tree | e2afde0c9c49c119a81f5cbcabd02d75ad7fe434 /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
parent | 418a7af455a62038df8227d7b3ed06b406174d08 (diff) | |
download | rails-3cfea287baa596833bd5e8bda5e12fd03250008f.tar.gz rails-3cfea287baa596833bd5e8bda5e12fd03250008f.tar.bz2 rails-3cfea287baa596833bd5e8bda5e12fd03250008f.zip |
Speed up class -> connection caching and stale connection verification. Closes #3979.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3693 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 8187112b64..a52d7f4fb0 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -21,10 +21,11 @@ module ActiveRecord class AbstractAdapter include Quoting, DatabaseStatements, SchemaStatements @@row_even = true - + def initialize(connection, logger = nil) #:nodoc: @connection, @logger = connection, logger @runtime = 0 + @last_verification = 0 end # Returns the human-readable name of the adapter. Use mixed case - one @@ -76,6 +77,15 @@ module ActiveRecord @active = false end + # Lazily verify this connection, calling +active?+ only if it hasn't + # been called for +timeout+ seconds. + def verify!(timeout) + now = Time.now.to_i + if (now - @last_verification) > timeout + reconnect! unless active? + @last_verification = now + end + end protected def log(sql, name) @@ -95,6 +105,9 @@ module ActiveRecord end rescue Exception => e # Log message and raise exception. + # Set last_verfication to 0, so that connection gets verified + # upon reentering the request loop + @last_verification = 0 message = "#{e.class.name}: #{e.message}: #{sql}" log_info(message, name, 0) raise ActiveRecord::StatementInvalid, message |