Skip to content

Commit 863d263

Browse files
tobiaskbrock
authored andcommitted
Added option to load QueriesNote even when NewRelic is installed.
1 parent c203763 commit 863d263

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

README

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Finally, you can control which notes you want to show. The default are:
6262

6363
Footnotes::Filter.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
6464

65+
The queries note by default will not load if it detects New Relic loaded in the app. If you want to load it
66+
in this case, add the following to an initializer:
67+
68+
Footnotes::Notes::QueriesNote.include_when_new_relic_installed = true if defined?(Footnotes)
6569

6670
Creating your own notes
6771
-----------------------

lib/rails-footnotes/notes/queries_note.rb

+32-13
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ class QueriesNote < AbstractNote
66
@@alert_db_time = 0.16
77
@@alert_sql_number = 8
88
@@sql = []
9-
cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :instance_writter => false
10-
9+
@@include_when_new_relic_installed = false
10+
@@loaded = false
11+
12+
cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :loaded, :instance_writter => false
13+
cattr_reader :include_when_new_relic_installed
14+
15+
def self.include_when_new_relic_installed=(include_me)
16+
@@include_when_new_relic_installed = include_me
17+
load if include_me
18+
end
19+
1120
def self.start!(controller)
1221
@@sql = []
1322
end
@@ -55,7 +64,26 @@ def content
5564

5665
return html
5766
end
67+
68+
def self.load
69+
#only include when NewRelic is installed if configured to do so
70+
if !loaded and
71+
defined?(ActiveRecord) and
72+
(!defined?(NewRelic) or
73+
include_when_new_relic_installed)
74+
if included?
75+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
76+
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
77+
next unless adapter =~ /.*[^Abstract]Adapter$/
78+
next if adapter =~ /SQLiteAdapter$/
79+
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
80+
end
81+
loaded = true
82+
end
83+
end
5884

85+
end
86+
5987
protected
6088
def parse_explain(results)
6189
table = []
@@ -161,14 +189,5 @@ def log_silence
161189

162190
end
163191
end
164-
#no need to run queries note if New Relic is installed
165-
if defined?(ActiveRecord) && !defined?(NewRelic)
166-
if Footnotes::Notes::QueriesNote.included?
167-
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
168-
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
169-
next unless adapter =~ /.*[^Abstract]Adapter$/
170-
next if adapter =~ /SQLiteAdapter$/
171-
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
172-
end
173-
end
174-
end
192+
193+
Footnotes::Notes::QueriesNote.load

0 commit comments

Comments
 (0)