Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Additional fixes for html escaping and new controller method name in …

…Rails 3
  • Loading branch information...
commit 5213ce31724aaa7d69677b455298080e9d9b122a 1 parent 64ba3f9
@nesquena nesquena authored
View
19 lib/query_reviewer/controller_extensions.rb
@@ -1,3 +1,4 @@
+require "action_view"
require File.join(File.dirname(__FILE__), "views", "query_review_box_helper")
module QueryReviewer
@@ -7,7 +8,10 @@ class QueryViewBase < ActionView::Base
end
def self.included(base)
- base.alias_method_chain :perform_action, :query_review if QueryReviewer::CONFIGURATION["inject_view"]
+ if QueryReviewer::CONFIGURATION["inject_view"]
+ alias_name = base.respond_to?(:perform_action) ? :perform_action : :process_action
+ base.alias_method_chain(alias_name, :query_review)
+ end
base.alias_method_chain :process, :query_review
base.helper_method :query_review_output
end
@@ -38,23 +42,24 @@ def add_query_output_to_view(total_time)
if response.body.is_a?(String) && response.body.match(/<\/body>/i) && Thread.current["queries"]
idx = (response.body =~ /<\/body>/i)
html = query_review_output(false, total_time)
- response.body.insert(idx, html)
+ response.body = response.body.insert(idx, html)
end
end
end
- def perform_action_with_query_review
+ def perform_action_with_query_review(*args)
Thread.current["query_reviewer_enabled"] = cookies["query_review_enabled"]
t1 = Time.now
- r = perform_action_without_query_review
+ r = self.respond_to?(:perform_action) ? perform_action_without_query_review(*args) : process_action_without_query_review(*args)
t2 = Time.now
add_query_output_to_view(t2 - t1)
r
end
+ alias_method :process_action_with_query_review, :perform_action_with_query_review
- def process_with_query_review(request, response, method = :perform_action, *arguments) #:nodoc:
+ def process_with_query_review(*args) #:nodoc:
Thread.current["queries"] = SqlQueryCollection.new
- process_without_query_review(request, response, method, *arguments)
+ process_without_query_review(*args)
end
end
-end
+end
View
3  lib/query_reviewer/views/query_review_box_helper.rb
@@ -84,13 +84,14 @@ def enabled_by_cookie
def duration_with_color(query)
title = query.duration_stats
duration = query.duration
- if duration > QueryReviewer::CONFIGURATION["critical_duration_threshold"]
+ span_html = if duration > QueryReviewer::CONFIGURATION["critical_duration_threshold"]
"<span style=\"color: #{severity_color(9)}\" title=\"#{title}\">#{"%.3f" % duration}</span>"
elsif duration > QueryReviewer::CONFIGURATION["warn_duration_threshold"]
"<span style=\"color: #{severity_color(QueryReviewer::CONFIGURATION["critical_severity"])}\" title=\"#{title}\">#{"%.3f" % duration}</span>"
else
"<span title=\"#{title}\">#{"%.3f" % duration}</span>"
end
+ span_html.respond_to?(:html_safe) ? span_html.html_safe : span_html
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.