Skip to content

Instantly share code, notes, and snippets.

@ebeigarts
Created December 28, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebeigarts/62547c525b5a452de5dc95915610d5a2 to your computer and use it in GitHub Desktop.
Save ebeigarts/62547c525b5a452de5dc95915610d5a2 to your computer and use it in GitHub Desktop.
if Rails.env.development?
ActionView::PathSet.class_eval do
private
alias_method :__find_all, :_find_all
def _find_all(*args)
t1 = Time.now
__find_all(*args)
ensure
t2 = Time.now
Thread.current["find_template_time"] ||= 0
Thread.current["find_template_time"] += (t2 - t1) * 1000
end
end
module TemplateResolverControllerRuntime
extend ActiveSupport::Concern
private
def process_action(action, *args)
Thread.current["find_template_time"] = 0
super
end
def append_info_to_payload(payload)
super
payload[:find_template_time] = Thread.current["find_template_time"] || 0
Thread.current["find_template_time"] = 0
end
module ClassMethods # :nodoc:
def log_process_action(payload)
messages, find_template_time = super, payload[:find_template_time]
messages << ("Resolver: %.1fms" % find_template_time.to_f) if find_template_time
messages
end
end
end
ActiveSupport.on_load(:action_controller) do
include TemplateResolverControllerRuntime
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment