-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:rails/rails
- Loading branch information
Showing
24 changed files
with
341 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'benchmark' | ||
require 'yaml' | ||
require 'set' | ||
require 'active_support/benchmarkable' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
activerecord/lib/active_record/railties/controller_runtime.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.