Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Dec 31, 2009
2 parents 5d8342c + c4c2502 commit 96c27e4
Show file tree
Hide file tree
Showing 24 changed files with 341 additions and 559 deletions.
3 changes: 1 addition & 2 deletions actionpack/lib/action_controller/rails.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module ActionController
class Plugin < Rails::Plugin
plugin_name :action_controller
include_modules_in "ActionController::Base"

initializer "action_controller.set_configs" do |app|
app.config.action_controller.each do |k,v|
Expand Down Expand Up @@ -91,4 +90,4 @@ class Plugin < Rails::Plugin
end

end
end
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require 'active_support/ruby/shim'
require 'active_support'
require 'active_support/dependencies/autoload'

require 'rack'
Expand Down
39 changes: 39 additions & 0 deletions actionpack/test/activerecord/controller_runtime_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'active_record_unit'
require 'active_record/railties/controller_runtime'
require 'fixtures/project'

ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime

class ARLoggingController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end

class ARLoggingTest < ActionController::TestCase
tests ARLoggingController

def setup
super
set_logger
end

def wait
ActiveSupport::Notifications.notifier.wait
end

def test_log_with_active_record
get :show
wait
assert_match /ActiveRecord runtime/, logs[3]
end

private
def set_logger
@controller.logger = MockLogger.new
end

def logs
@logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip}
end
end
1 change: 0 additions & 1 deletion activerecord/lib/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module ActiveRecord
autoload :Batches
autoload :Calculations
autoload :Callbacks
autoload :ControllerRuntime
autoload :DynamicFinderMatch
autoload :DynamicScopeMatch
autoload :Migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,14 @@ def remove_records(*records)

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

Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'benchmark'
require 'yaml'
require 'set'
require 'active_support/benchmarkable'
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def destroy_with_callbacks #:nodoc:

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -191,16 +192,19 @@ def current_savepoint_name
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(' ')))
end
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
Expand Down
27 changes: 0 additions & 27 deletions activerecord/lib/active_record/controller_runtime.rb

This file was deleted.

15 changes: 9 additions & 6 deletions activerecord/lib/active_record/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
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|
Expand All @@ -33,6 +30,12 @@ class Plugin < Rails::Plugin
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
Expand All @@ -51,7 +54,7 @@ class Plugin < Rails::Plugin

# 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
Expand All @@ -63,4 +66,4 @@ class Plugin < Rails::Plugin
end

end
end
end
31 changes: 31 additions & 0 deletions activerecord/lib/active_record/railties/controller_runtime.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions activerecord/lib/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def initialize(record)

module Validations
extend ActiveSupport::Concern

include ActiveSupport::DeprecatedCallbacks
include ActiveModel::Validations

included do
Expand Down
1 change: 0 additions & 1 deletion activesupport/lib/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ module ActiveSupport
autoload :Callbacks
autoload :Concern
autoload :Configurable
autoload :DeprecatedCallbacks
autoload :Deprecation
autoload :Gzip
autoload :Inflector
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_callbacks(kind, *args, &block)
class Callback
@@_callback_sequence = 0

attr_accessor :chain, :filter, :kind, :options, :per_key, :klass
attr_accessor :chain, :filter, :kind, :options, :per_key, :klass, :raw_filter

def initialize(chain, filter, kind, options, klass)
@chain, @kind, @klass = chain, kind, klass
Expand Down
Loading

0 comments on commit 96c27e4

Please sign in to comment.