Disable logging of Columns queries?

11 views
Skip to first unread message

korch

unread,
Nov 4, 2009, 1:51:04 AM11/4/09
to Oracle enhanced adapter for ActiveRecord
Question: I'd like to disable the adapter from logging all the SQL
queries to the all_tabs_columns table, but I don't see a way to do it.
Is this a current feature? I checked the documentation first, but
didn't find it. I never need to see those queries in the ActiveRecord
logger while in development mode, so I'd like to make my logs more
readable.

Regards,

Raimonds Simanovskis

unread,
Nov 4, 2009, 2:56:05 AM11/4/09
to Oracle enhanced adapter for ActiveRecord
Currently there is no way to disable logging of this query - all SQL
queries are logged in development mode.
And in development mode model classes are reloaded for each request
and therefore during each request processing SQL query is made to get
all table columns for each used model.

There is one "monkey patch" that we use in some our projects that
disables reloading of column information during each request:
### put this in lib/cache_columns.rb
module ActiveRecord
module ConnectionAdapters
class OracleEnhancedAdapter < AbstractAdapter
# Cache column descriptions between requests
@@cache_columns = false
cattr_accessor :cache_columns

def columns_with_cache(table_name, name = nil)
# Don't double cache if config.cache_classes is turned on
if self.class.cache_columns && !(defined?(Rails) &&
Rails.configuration.cache_classes)
@@columns_cache ||= {}
@@columns_cache[table_name] ||= columns_without_cache
(table_name, name)
else
columns_without_cache(table_name, name)
end
end

alias_method_chain :columns, :cache
end
end
end

### include this in some initializer file, e.g. config/initializers/
oracle.rb
# Cache column descriptions between requests
if RAILS_ENV == 'development'
require "cache_columns"

ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns
= true
end

As a result table column information will be cached between requests
in development mode and you will not see SELECTs from all_tabs_columns
for each request. This will also speed up a little bit performance in
development mode (especially if Oracle database in development
environment is not on your local machine). But if you change table
columns then you will need to restart Rails application.

Probably I need to add this to the next version of oracle_enhanced.

Raimonds

Lori Olson

unread,
Nov 4, 2009, 12:40:10 PM11/4/09
to oracle-...@googlegroups.com
That sounds really useful, Raimonds.  And it would speed up development for me.

korch

unread,
Nov 4, 2009, 3:18:13 PM11/4/09
to Oracle enhanced adapter for ActiveRecord
I was able to successfully suppress the extra sql logging with that
monkey patch—thanks so much!

Regards,
Reply all
Reply to author
Forward
0 new messages