Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping cached queries. #10

Merged
merged 1 commit into from
Mar 5, 2015

Conversation

tinynumbers
Copy link
Contributor

I've added a new :ignore_cached_queries configuration option to prevent output of the backtrace for cached queries.

This is useful if you are only interested in tracking down the origin of database queries that actually hit the database.

Set this option to true...

ActiveRecordQueryTrace.enabled = true
ActiveRecordQueryTrace.ignore_cached_queries = true

...and backtrace output will not occur for any SQL query that uses cached results (i.e. those SQL queries that would show up in the log prefixed with CACHE).

I'm using this in conjunction with a custom logger in development that also skips logging of cached queries.. In development.rb,

  # Don't log cached queries
  class LogWithoutCachedQueries < ::Logger
    def debug(message, *args, &block)
      unless message.include? 'CACHE ('
        super
      end
    end
  end

  # Default is 1GB!  Let's limit to 3 5MB files
  max_log_files = 3
  max_log_size = 5 * 1024 * 1024
  log_file = Rails.root.join('log', Rails.env + '.log')

  config.logger = LogWithoutCachedQueries.new(log_file, max_log_files, max_log_size)

ruckus added a commit that referenced this pull request Mar 5, 2015
@ruckus ruckus merged commit c08a233 into brunofacca:master Mar 5, 2015
@ruckus
Copy link
Collaborator

ruckus commented Mar 5, 2015

Awesome, thank you! Great addition, should clean up lots of clutter.

@tinynumbers
Copy link
Contributor Author

Great - thanks for the quick merge! Would it be possible to roll up as a new version 1.4 release of the gem?

@ruckus
Copy link
Collaborator

ruckus commented Mar 5, 2015

Absolutely, 1.4 pushed to RubyGems.

https://rubygems.org/gems/active_record_query_trace

@tinynumbers tinynumbers deleted the ignore-cached-queries branch March 18, 2015 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants