diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-31 01:15:30 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2009-12-31 01:15:30 -0500 |
commit | 96c27e4003b803b9ac1a3581dfe1c181ba79556a (patch) | |
tree | 24a6c8573dfe3aa01abd4464eafbeb86e96cd250 /activerecord | |
parent | 5d8342cc325bc9f46bfe61bf3534248b6ad3216f (diff) | |
parent | c4c2502df8b0b7b5fa28d796bdb1d4bd02af4b3d (diff) | |
download | rails-96c27e4003b803b9ac1a3581dfe1c181ba79556a.tar.gz rails-96c27e4003b803b9ac1a3581dfe1c181ba79556a.tar.bz2 rails-96c27e4003b803b9ac1a3581dfe1c181ba79556a.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 9 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/controller_runtime.rb | 27 | ||||
-rw-r--r-- | activerecord/lib/active_record/rails.rb | 15 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/controller_runtime.rb | 31 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake (renamed from activerecord/lib/active_record/rails/databases.rake) | 0 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 2 |
10 files changed, 56 insertions, 42 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 87de480263..a524dc50a1 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -60,7 +60,6 @@ module ActiveRecord autoload :Batches autoload :Calculations autoload :Callbacks - autoload :ControllerRuntime autoload :DynamicFinderMatch autoload :DynamicScopeMatch autoload :Migration diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b2b3a9789c..1ceb0dbf96 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -485,7 +485,14 @@ module ActiveRecord def callback(method, record) callbacks_for(method).each do |callback| - ActiveSupport::DeprecatedCallbacks::Callback.new(method, callback, record).call(@owner, record) + case callback + when Symbol + @owner.send(callback, record) + when Proc + callback.call(@owner, record) + else + callback.send(method, @owner, record) + end end end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 07c5545171..c4bdbdad08 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,4 +1,3 @@ -require 'benchmark' require 'yaml' require 'set' require 'active_support/benchmarkable' diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index e1d772bd95..e2a8f03c8f 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -274,7 +274,7 @@ module ActiveRecord def deprecated_callback_method(symbol) #:nodoc: if respond_to?(symbol) - ActiveSupport::Deprecation.warn("Base##{symbol} has been deprecated, please use Base.#{symbol} :method instead") + ActiveSupport::Deprecation.warn("Overwriting #{symbol} in your models has been deprecated, please use Base##{symbol} :method_name instead") send(symbol) end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 8fae26b790..d09aa3c4d2 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -1,6 +1,7 @@ require 'date' require 'bigdecimal' require 'bigdecimal/util' +require 'active_support/core_ext/benchmark' # TODO: Autoload these files require 'active_record/connection_adapters/abstract/schema_definitions' @@ -191,7 +192,6 @@ module ActiveRecord end def log_info(sql, name, ms) - @runtime += ms if @logger && @logger.debug? name = '%s (%.1fms)' % [name || 'SQL', ms] @logger.debug(format_log_entry(name, sql.squeeze(' '))) @@ -199,8 +199,12 @@ module ActiveRecord end protected - def log(sql, name, &block) - ActiveSupport::Notifications.instrument(:sql, :sql => sql, :name => name, &block) + def log(sql, name) + result = nil + ActiveSupport::Notifications.instrument(:sql, :sql => sql, :name => name) do + @runtime += Benchmark.ms { result = yield } + end + result rescue Exception => e # Log message and raise exception. # Set last_verification to 0, so that connection gets verified diff --git a/activerecord/lib/active_record/controller_runtime.rb b/activerecord/lib/active_record/controller_runtime.rb deleted file mode 100644 index 1281901ae8..0000000000 --- a/activerecord/lib/active_record/controller_runtime.rb +++ /dev/null @@ -1,27 +0,0 @@ -module ActiveRecord - module ControllerRuntime - extend ActiveSupport::Concern - - attr_internal :db_runtime - - def cleanup_view_runtime - if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - db_rt_before_render = ActiveRecord::Base.connection.reset_runtime - runtime = super - db_rt_after_render = ActiveRecord::Base.connection.reset_runtime - self.db_runtime = db_rt_before_render + db_rt_after_render - runtime - db_rt_after_render - else - super - end - end - - module ClassMethods - def process_log_action(controller) - super - db_runtime = controller.send :db_runtime - logger.info(" ActiveRecord runtime: %.1fms" % db_runtime.to_f) if db_runtime - end - end - end -end
\ No newline at end of file diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/rails.rb index e7de699974..a13bd2a5da 100644 --- a/activerecord/lib/active_record/rails.rb +++ b/activerecord/lib/active_record/rails.rb @@ -7,12 +7,9 @@ require "action_controller/rails" module ActiveRecord class Plugin < Rails::Plugin plugin_name :active_record - include_modules_in "ActiveRecord::Base" - - config.action_controller.include "ActiveRecord::ControllerRuntime" rake_tasks do - load "active_record/rails/databases.rake" + load "active_record/railties/databases.rake" end initializer "active_record.set_configs" do |app| @@ -33,6 +30,12 @@ module ActiveRecord ActiveRecord::Base.default_timezone = :utc end + # Expose database runtime to controller for logging. + initializer "active_record.log_runtime" do |app| + require "active_record/railties/controller_runtime" + ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime + end + # Setup database middleware after initializers have run initializer "active_record.initialize_database_middleware" do |app| middleware = app.config.middleware @@ -51,7 +54,7 @@ module ActiveRecord # TODO: ActiveRecord::Base.logger should delegate to its own config.logger initializer "active_record.logger" do - ActiveRecord::Base.logger ||= Rails.logger + ActiveRecord::Base.logger ||= ::Rails.logger end initializer "active_record.notifications" do @@ -63,4 +66,4 @@ module ActiveRecord end end -end
\ No newline at end of file +end diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb new file mode 100644 index 0000000000..535e967ec3 --- /dev/null +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -0,0 +1,31 @@ +require 'active_support/core_ext/module/attr_internal' + +module ActiveRecord + module Railties + module ControllerRuntime + extend ActiveSupport::Concern + + attr_internal :db_runtime + + def cleanup_view_runtime + if ActiveRecord::Base.connected? + db_rt_before_render = ActiveRecord::Base.connection.reset_runtime + runtime = super + db_rt_after_render = ActiveRecord::Base.connection.reset_runtime + self.db_runtime = db_rt_before_render + db_rt_after_render + runtime - db_rt_after_render + else + super + end + end + + module ClassMethods + def log_process_action(controller) + super + db_runtime = controller.send :db_runtime + logger.info(" ActiveRecord runtime: %.1fms" % db_runtime.to_f) if db_runtime + end + end + end + end +end diff --git a/activerecord/lib/active_record/rails/databases.rake b/activerecord/lib/active_record/railties/databases.rake index a35a6c156b..a35a6c156b 100644 --- a/activerecord/lib/active_record/rails/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index e8a2a72735..12c1f23763 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -17,8 +17,6 @@ module ActiveRecord module Validations extend ActiveSupport::Concern - - include ActiveSupport::DeprecatedCallbacks include ActiveModel::Validations included do |