From 8d3e5c8c5200880a66abef3fd2f45104e65732e9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 14 Mar 2013 22:42:12 -0700 Subject: hide more data in the schema cache --- .../associations/association_scope.rb | 2 +- .../connection_adapters/schema_cache.rb | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index c5fb1fe2c7..a9525436fb 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -22,7 +22,7 @@ module ActiveRecord private def column_for(table_name, column_name) - columns = alias_tracker.connection.schema_cache.columns_hash[table_name] + columns = alias_tracker.connection.schema_cache.columns_hash(table_name) columns[column_name] end diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index b516518126..9c56d35bcc 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -1,7 +1,9 @@ +require 'active_support/deprecation/reporting' + module ActiveRecord module ConnectionAdapters class SchemaCache - attr_reader :tables, :version + attr_reader :version attr_accessor :connection def initialize(conn) @@ -18,6 +20,7 @@ module ActiveRecord if table_name @primary_keys[table_name] else + ActiveSupport::Deprecation.warn('call primary_keys with a table name!') @primary_keys.dup end end @@ -38,11 +41,21 @@ module ActiveRecord end end + def tables(name = nil) + if name + @tables[name] + else + ActiveSupport::Deprecation.warn('call tables with a name!') + @tables.dup + end + end + # Get the columns for a table def columns(table = nil) if table @columns[table] else + ActiveSupport::Deprecation.warn('call columns with a table name!') @columns.dup end end @@ -53,6 +66,7 @@ module ActiveRecord if table @columns_hash[table] else + ActiveSupport::Deprecation.warn('call columns_hash with a table name!') @columns_hash.dup end end @@ -66,6 +80,12 @@ module ActiveRecord @version = nil end + def size + [@columns, @columns_hash, @primary_keys, @tables].map { |x| + x.size + }.inject :+ + end + # Clear out internal caches for table with +table_name+. def clear_table_cache!(table_name) @columns.delete table_name -- cgit v1.2.3