Class: Footnotes::Notes::QueriesNote
Class Method Summary
collapse
Instance Method Summary
collapse
close!, #escape, #has_fieldset?, #hash_to_xml_attributes, included?, #initialize, #javascript, #legend, #link, #mount_table, #mount_table_for_hash, #onclick, #prefix?, #row, #stylesheet, title, #to_sym, to_sym, #valid?
Class Method Details
.query_subscriber ⇒ Object
13
14
15
|
# File 'lib/rails-footnotes/notes/queries_note.rb', line 13
def self.query_subscriber
@@query_subscriber ||= Footnotes::Notes::QuerySubscriber.new(self.orm)
end
|
.start!(controller) ⇒ Object
9
10
11
|
# File 'lib/rails-footnotes/notes/queries_note.rb', line 9
def self.start!(controller)
self.query_subscriber.reset!
end
|
Instance Method Details
#content ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rails-footnotes/notes/queries_note.rb', line 33
def content
html = '<table>'
self.events.each_with_index do |event, index|
sql_links = []
sql_links << "<a href=\"javascript:Footnotes.toggle('qtrace_#{index}')\" style=\"color:#00A;\">trace</a>"
html << <<-HTML
<tr>
<td>
<b id="qtitle_#{index}">#{escape(event.type.to_s.upcase)}</b> (#{sql_links.join(' | ')})
<p id="qtrace_#{index}" style="display:none;">#{parse_trace(event.trace)}</p><br />
</td>
<td>
<span id="sql_#{index}">#{print_query(event.payload[:sql])}</span>
</td>
<td>#{print_name_and_time(event.payload[:name], event.duration)}</td>
</tr>
HTML
end
html << '</table>'
return html
end
|
#events ⇒ Object
17
18
19
|
# File 'lib/rails-footnotes/notes/queries_note.rb', line 17
def events
self.class.query_subscriber.events
end
|
#title ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/rails-footnotes/notes/queries_note.rb', line 21
def title
queries = self.events.count
total_time = self.events.map(&:duration).sum
query_color = alert_color(self.events.count, alert_sql_number)
db_color = alert_color(total_time, alert_db_time)
<<-TITLE
<span style="background-color:#{query_color}">Queries (#{queries})</span>
<span style="background-color:#{db_color}">DB (#{"%.3f" % total_time}ms)</span>
TITLE
end
|