Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #13 from mikegee/issue-12-dynamically-load-unload-…

…per-request

dynamically enabled per request based on session
  • Loading branch information...
commit 43b46f92afbc81ae7da8459ff3ae9afa465fe4e8 2 parents 2fb2600 + 1dea755
@nesquena authored
View
8 lib/query_reviewer/controller_extensions.rb
@@ -30,6 +30,8 @@ def query_review_output(ajax = false, total_time = nil)
end
def add_query_output_to_view(total_time)
+ return unless Thread.current["query_reviewer_enabled"]
+
if request.xhr?
if cookies["query_review_enabled"]
if !response.content_type || response.content_type.include?("text/html")
@@ -48,7 +50,9 @@ def add_query_output_to_view(total_time)
end
def perform_action_with_query_review(*args)
- Thread.current["query_reviewer_enabled"] = cookies["query_review_enabled"]
+ Thread.current["query_reviewer_enabled"] = (CONFIGURATION["enabled"] == true and cookies["query_review_enabled"]) ||
+ (CONFIGURATION["enabled"] == "based_on_session" and session["query_review_enabled"])
+
t1 = Time.now
r = defined?(Rails::Railtie) ? process_action_without_query_review(*args) : perform_action_without_query_review(*args)
t2 = Time.now
@@ -62,4 +66,4 @@ def process_with_query_review(*args) #:nodoc:
process_without_query_review(*args)
end
end
-end
+end
View
12 lib/query_reviewer/mysql_adapter_extensions.rb
@@ -6,7 +6,7 @@ def self.included(base)
base.alias_method_chain :insert, :review
base.alias_method_chain :delete, :review
end
-
+
def update_with_review(sql, *args)
t1 = Time.now
result = update_without_review(sql, *args)
@@ -36,8 +36,10 @@ def delete_with_review(sql, *args)
result
end
-
+
def select_with_review(sql, *args)
+ return select_without_review(sql, *args) unless query_reviewer_enabled?
+
sql.gsub!(/^SELECT /i, "SELECT SQL_NO_CACHE ") if QueryReviewer::CONFIGURATION["disable_sql_cache"]
QueryReviewer.safe_log { execute("SET PROFILING=1") } if QueryReviewer::CONFIGURATION["profiling"]
t1 = Time.now
@@ -73,11 +75,11 @@ def select_with_review(sql, *args)
end
query_results
end
-
+
def query_reviewer_enabled?
Thread.current["queries"] && Thread.current["queries"].respond_to?(:find_or_create_sql_query) && Thread.current["query_reviewer_enabled"]
end
-
+
def create_or_add_query_to_query_reviewer!(sql, cols, run_time, profile, command = "SELECT", affected_rows = 1)
if query_reviewer_enabled?
t1 = Time.now
@@ -87,4 +89,4 @@ def create_or_add_query_to_query_reviewer!(sql, cols, run_time, profile, command
end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.