Skip to content

Commit

Permalink
Added option to load QueriesNote even when NewRelic is installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias authored and kbrock committed Jan 26, 2010
1 parent c203763 commit 863d263
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Finally, you can control which notes you want to show. The default are:

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

The queries note by default will not load if it detects New Relic loaded in the app. If you want to load it
in this case, add the following to an initializer:

Footnotes::Notes::QueriesNote.include_when_new_relic_installed = true if defined?(Footnotes)

Creating your own notes
-----------------------
Expand Down
45 changes: 32 additions & 13 deletions lib/rails-footnotes/notes/queries_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ class QueriesNote < AbstractNote
@@alert_db_time = 0.16
@@alert_sql_number = 8
@@sql = []
cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :instance_writter => false

@@include_when_new_relic_installed = false
@@loaded = false

cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :loaded, :instance_writter => false
cattr_reader :include_when_new_relic_installed

def self.include_when_new_relic_installed=(include_me)
@@include_when_new_relic_installed = include_me
load if include_me
end

def self.start!(controller)
@@sql = []
end
Expand Down Expand Up @@ -55,7 +64,26 @@ def content

return html
end

def self.load
#only include when NewRelic is installed if configured to do so
if !loaded and
defined?(ActiveRecord) and
(!defined?(NewRelic) or
include_when_new_relic_installed)
if included?
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
next unless adapter =~ /.*[^Abstract]Adapter$/
next if adapter =~ /SQLiteAdapter$/
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
end
loaded = true
end
end

end

protected
def parse_explain(results)
table = []
Expand Down Expand Up @@ -161,14 +189,5 @@ def log_silence

end
end
#no need to run queries note if New Relic is installed
if defined?(ActiveRecord) && !defined?(NewRelic)
if Footnotes::Notes::QueriesNote.included?
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
next unless adapter =~ /.*[^Abstract]Adapter$/
next if adapter =~ /SQLiteAdapter$/
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
end
end
end

Footnotes::Notes::QueriesNote.load

0 comments on commit 863d263

Please sign in to comment.