query_reviewer 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/query_reviewer/controller_extensions.rb +6 -2
- data/lib/query_reviewer/mysql_adapter_extensions.rb +8 -6
- data/lib/query_reviewer/views/_box_body.html.erb +30 -30
- data/lib/query_reviewer/views/_box_disabled.html.erb +1 -1
- data/lib/query_reviewer/views/_query_trace.html.erb +2 -2
- data/lib/query_reviewer/views/_query_with_warning.html.erb +7 -7
- metadata +22 -42
@@ -30,6 +30,8 @@ module QueryReviewer
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_query_output_to_view(total_time)
|
33
|
+
return unless Thread.current["query_reviewer_enabled"]
|
34
|
+
|
33
35
|
if request.xhr?
|
34
36
|
if cookies["query_review_enabled"]
|
35
37
|
if !response.content_type || response.content_type.include?("text/html")
|
@@ -48,7 +50,9 @@ module QueryReviewer
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def perform_action_with_query_review(*args)
|
51
|
-
Thread.current["query_reviewer_enabled"] = cookies["query_review_enabled"]
|
53
|
+
Thread.current["query_reviewer_enabled"] = (CONFIGURATION["enabled"] == true and cookies["query_review_enabled"]) ||
|
54
|
+
(CONFIGURATION["enabled"] == "based_on_session" and session["query_review_enabled"])
|
55
|
+
|
52
56
|
t1 = Time.now
|
53
57
|
r = defined?(Rails::Railtie) ? process_action_without_query_review(*args) : perform_action_without_query_review(*args)
|
54
58
|
t2 = Time.now
|
@@ -62,4 +66,4 @@ module QueryReviewer
|
|
62
66
|
process_without_query_review(*args)
|
63
67
|
end
|
64
68
|
end
|
65
|
-
end
|
69
|
+
end
|
@@ -6,7 +6,7 @@ module QueryReviewer
|
|
6
6
|
base.alias_method_chain :insert, :review
|
7
7
|
base.alias_method_chain :delete, :review
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def update_with_review(sql, *args)
|
11
11
|
t1 = Time.now
|
12
12
|
result = update_without_review(sql, *args)
|
@@ -36,15 +36,17 @@ module QueryReviewer
|
|
36
36
|
|
37
37
|
result
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def select_with_review(sql, *args)
|
41
|
+
return select_without_review(sql, *args) unless query_reviewer_enabled?
|
42
|
+
|
41
43
|
sql.gsub!(/^SELECT /i, "SELECT SQL_NO_CACHE ") if QueryReviewer::CONFIGURATION["disable_sql_cache"]
|
42
44
|
QueryReviewer.safe_log { execute("SET PROFILING=1") } if QueryReviewer::CONFIGURATION["profiling"]
|
43
45
|
t1 = Time.now
|
44
46
|
query_results = select_without_review(sql, *args)
|
45
47
|
t2 = Time.now
|
46
48
|
|
47
|
-
if @logger && sql =~ /^select/i
|
49
|
+
if @logger && query_reviewer_enabled? && sql =~ /^select/i
|
48
50
|
use_profiling = QueryReviewer::CONFIGURATION["profiling"]
|
49
51
|
use_profiling &&= (t2 - t1) >= QueryReviewer::CONFIGURATION["warn_duration_threshold"].to_f / 2.0 if QueryReviewer::CONFIGURATION["production_data"]
|
50
52
|
|
@@ -73,11 +75,11 @@ module QueryReviewer
|
|
73
75
|
end
|
74
76
|
query_results
|
75
77
|
end
|
76
|
-
|
78
|
+
|
77
79
|
def query_reviewer_enabled?
|
78
80
|
Thread.current["queries"] && Thread.current["queries"].respond_to?(:find_or_create_sql_query) && Thread.current["query_reviewer_enabled"]
|
79
81
|
end
|
80
|
-
|
82
|
+
|
81
83
|
def create_or_add_query_to_query_reviewer!(sql, cols, run_time, profile, command = "SELECT", affected_rows = 1)
|
82
84
|
if query_reviewer_enabled?
|
83
85
|
t1 = Time.now
|
@@ -87,4 +89,4 @@ module QueryReviewer
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
90
|
-
end
|
92
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
|
1
|
+
<p>Total queries: <span class="number"><%= @queries.query_count %></span>
|
2
2
|
<% if @total_time %>Total time: <span class="number" title="TOTAL TIME: <%= @total_time %>s QR_OVERHEAD: <%= @queries.overhead_time %>s">
|
3
3
|
<%= '%.3f' % (@total_time - @queries.overhead_time) %></span>s
|
4
4
|
<% end %>
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
Database Time: <span class="number"><%= '%.3f' % @queries.total_duration %></span>s</p>
|
6
|
+
<p class="indent">With warnings: <span class="number bad"><%= @queries.total_with_warnings %></span> (<%= @queries.percent_with_warnings %>%)</p>
|
7
|
+
<p class="indent">Without warnings: <span class="number good"><%= @queries.total_without_warnings %></span> (<%= @queries.percent_without_warnings %>%)</p>
|
8
8
|
<p>Type:
|
9
9
|
<% QueryReviewer::SqlQueryCollection::COMMANDS.each do |command| %>
|
10
10
|
<% next if @queries.count_of_command(command).zero? %>
|
11
11
|
<span class="number"><%= @queries.count_of_command(command) %></span> <%= command %>s
|
12
12
|
<% end %>
|
13
13
|
</p>
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
14
|
+
<% if warnings_no_query_sorted.length + queries_with_warnings_sorted.length > 0 %>
|
15
|
+
<div class="divider"></div>
|
16
|
+
<% if warnings_no_query_sorted_nonignored.length + queries_with_warnings_sorted_nonignored.length > 0 %>
|
17
|
+
<p class="title"><%= warnings_no_query_sorted_nonignored.length + queries_with_warnings_sorted_nonignored.length %> Errors:</p>
|
18
|
+
<ul>
|
19
|
+
<%= render :partial => "/warning_no_query", :collection => warnings_no_query_sorted_nonignored %>
|
20
|
+
<%= render :partial => "/query_with_warning", :collection => queries_with_warnings_sorted_nonignored %>
|
21
|
+
</ul>
|
22
|
+
<% end %>
|
23
|
+
<% if warnings_no_query_sorted_ignored.length + queries_with_warnings_sorted_ignored.length > 0 %>
|
24
|
+
<%= warnings_no_query_sorted_ignored.length + queries_with_warnings_sorted_ignored.length %> Warnings:
|
25
|
+
<ul id="query_review_ignored_warnings">
|
26
|
+
<%= render :partial => "/warning_no_query", :collection => warnings_no_query_sorted_ignored %>
|
27
|
+
<%= render :partial => "/query_with_warning", :collection => queries_with_warnings_sorted_ignored %>
|
28
|
+
</ul>
|
29
|
+
<% end %>
|
30
|
+
<% end %>
|
31
|
+
<div class="divider"></div>
|
32
|
+
<p class="title">Safe queries:</p>
|
33
|
+
<% if @queries.queries.empty? %>
|
34
|
+
No queries to display.
|
35
|
+
<% else %>
|
36
36
|
<% QueryReviewer::SqlQueryCollection::COMMANDS.reverse.each do |command| %>
|
37
37
|
<% next if @queries.count_of_command(command, true).zero? %>
|
38
38
|
<ul class="small">
|
@@ -48,12 +48,12 @@
|
|
48
48
|
<% end %>
|
49
49
|
<%= render :partial => "/query_sql", :locals=>{ :query_sql => query } %>
|
50
50
|
<% if query.select? %>
|
51
|
-
<a href="
|
51
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query.id %>_explain')" title="show/hide sql">EXPLN</a>
|
52
52
|
<% end %>
|
53
53
|
<% if QueryReviewer::CONFIGURATION["profiling"] && query.profile %>
|
54
|
-
<a href="
|
54
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query.id %>_profile')" title="show/hide profile">PROF</a>
|
55
55
|
<% end %>
|
56
|
-
<a href="
|
56
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query.id %>_trace')" title="show/hide stack trace">TRACE</a>
|
57
57
|
<div style="display: none" id="warning_<%= query.id %>_explain" class="indent small tbpadded">
|
58
58
|
<%= render :partial => "/explain", :locals => {:query => query} %>
|
59
59
|
</div>
|
@@ -70,4 +70,4 @@
|
|
70
70
|
</ul>
|
71
71
|
<% end %>
|
72
72
|
<% end %>
|
73
|
-
<p id="query_review_disable_link"><a href="
|
73
|
+
<p id="query_review_disable_link"><a href="#" onclick="eraseCookie('query_review_enabled'); query_review_hide('query_review_disable_link'); alert('Cookie successfully set.');">Disable analysis report</a> on next page load and from now on.</p>
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<p>SQL analysis has been disabled for you. A cookie must be set to enable analysis. This generally slows down your browser, so it's only recommended for users analyzing SQL queries.</p>
|
2
|
-
<p id="query_review_enable_link"><b><a href="
|
2
|
+
<p id="query_review_enable_link"><b><a href="#" onclick="createCookie('query_review_enabled', '1'); query_review_hide('query_review_enable_link'); alert('Cookie successfully set.');">Enabled it</a> on next page load and from now on.</b></p>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
13
13
|
</code>
|
14
|
-
<a href="
|
14
|
+
<a href="#" onclick="query_review_toggle('trace_<%= query_id %>_abridged'); query_review_toggle('trace_<%= query_id %>_full')" title="show full trace">FULL</a>
|
15
15
|
</div>
|
16
16
|
|
17
17
|
<div class="trace" style="display: none; max-height: 300px; overflow: scroll" id="trace_<%= query_id %>_full">
|
@@ -27,5 +27,5 @@
|
|
27
27
|
<% end %>
|
28
28
|
<% end %>
|
29
29
|
</code>
|
30
|
-
<a href="
|
30
|
+
<a href="#" onclick="query_review_toggle('trace_<%= query_id %>_abridged'); query_review_toggle('trace_<%= query_id %>_full')" title="show short trace">SHORT</a>
|
31
31
|
</div>
|
@@ -16,19 +16,19 @@
|
|
16
16
|
<% query_with_warning.warnings.sort{|a,b| a.severity <=> b.severity}.reverse.each_with_index do |warn, index| %>
|
17
17
|
<span style="color: <%= severity_color warn.severity%>;" title="<%= warn.desc%>"><%= warn.problem %></span><%= ", " if index < query_with_warning.warnings.length - 1 %>
|
18
18
|
<% end %>
|
19
|
-
<a href="
|
20
|
-
<a href="
|
19
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query_with_warning.id %>_desc')" title="show/hide warning message">MSG</a>
|
20
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query_with_warning.id %>_sql')" title="show/hide sql">SQL</a>
|
21
21
|
<% if query_with_warning.select? %>
|
22
|
-
<a href="
|
22
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query_with_warning.id %>_explain')" title="show/hide explain output">EXPLN</a>
|
23
23
|
<% end %>
|
24
24
|
<% if QueryReviewer::CONFIGURATION["profiling"] && query_with_warning.profile %>
|
25
|
-
<a href="
|
25
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query_with_warning.id %>_profile')" title="show/hide profile output">PROF</a>
|
26
26
|
<% end %>
|
27
|
-
<a href="
|
27
|
+
<a href="#" onclick="query_review_toggle('warning_<%= query_with_warning.id %>_trace')" title="show/hide stack trace">TRACE</a>
|
28
28
|
<% if ignore_hash?(query_with_warning.to_hash) %>
|
29
|
-
<a href="
|
29
|
+
<a href="#" onclick="remove_ignore_hash('<%= query_with_warning.to_hash %>'); query_review_hide('query_<%= query_with_warning.id %>')" title="stop ignore this query from now on">UNIGNR</a>
|
30
30
|
<% else %>
|
31
|
-
<a href="
|
31
|
+
<a href="#" onclick="add_ignore_hash('<%= query_with_warning.to_hash %>'); query_review_hide('query_<%= query_with_warning.id %>')" title="ignoring this query from now on">IGNR</a>
|
32
32
|
<% end %>
|
33
33
|
</p>
|
34
34
|
</div>
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_reviewer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- dsboulder, nesquena
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-02-13 00:00:00 -08:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: Runs explain before each select query and displays results in an overlayed
|
15
|
+
div
|
23
16
|
email: nesquena@gmail.com
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- MIT-LICENSE
|
32
22
|
- Rakefile
|
33
23
|
- README.md
|
@@ -59,39 +49,29 @@ files:
|
|
59
49
|
- lib/query_reviewer/views/_warning_no_query.html.erb
|
60
50
|
- lib/query_reviewer/views/query_review_box_helper.rb
|
61
51
|
- lib/query_reviewer.rb
|
62
|
-
has_rdoc: true
|
63
52
|
homepage: https://github.com/nesquena/query_reviewer
|
64
53
|
licenses: []
|
65
|
-
|
66
54
|
post_install_message:
|
67
55
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
56
|
+
require_paths:
|
70
57
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
59
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
65
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
89
70
|
requirements: []
|
90
|
-
|
91
71
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.8.24
|
93
73
|
signing_key:
|
94
74
|
specification_version: 3
|
95
|
-
summary: Runs explain before each select query and displays results in an overlayed
|
75
|
+
summary: Runs explain before each select query and displays results in an overlayed
|
76
|
+
div
|
96
77
|
test_files: []
|
97
|
-
|