Created
October 4, 2010 16:00
-
-
Save alanho/609936 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Mongo | |
module ControllerRuntime | |
extend ActiveSupport::Concern | |
protected | |
attr_internal :mongo_runtime | |
def cleanup_view_runtime | |
mongo_rt_before_render = MongoInstrumenter::LogSubscriber.reset_runtime | |
runtime = super | |
mongo_rt_after_render = MongoInstrumenter::LogSubscriber.reset_runtime | |
self.mongo_runtime = mongo_rt_before_render + mongo_rt_after_render | |
runtime - mongo_rt_after_render | |
end | |
def append_info_to_payload(payload) | |
super | |
payload[:mongo_runtime] = mongo_runtime | |
end | |
module ClassMethods | |
def log_process_action(payload) | |
messages, mongo_runtime = super, payload[:mongo_runtime] | |
messages << ("Mongoid: %.1fms" % mongo_runtime.to_f) if mongo_runtime | |
messages | |
end | |
end | |
end | |
class Railtie < Rails::Railtie | |
# Expose mongoid runtime to controller for logging. | |
initializer "mongoid.log_runtime" do |app| | |
ActiveSupport.on_load(:action_controller) do | |
include ControllerRuntime | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment