diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/statement_pool.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/statement_pool.rb | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/statement_pool.rb b/activerecord/lib/active_record/connection_adapters/statement_pool.rb index 82e9ef3d3d..46bd831da7 100644 --- a/activerecord/lib/active_record/connection_adapters/statement_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/statement_pool.rb @@ -1,12 +1,15 @@ +# frozen_string_literal: true + module ActiveRecord module ConnectionAdapters - class StatementPool + class StatementPool # :nodoc: include Enumerable - def initialize(connection, max = 1000) - @cache = Hash.new { |h,pid| h[pid] = {} } - @connection = connection - @max = max + DEFAULT_STATEMENT_LIMIT = 1000 + + def initialize(statement_limit = nil) + @cache = Hash.new { |h, pid| h[pid] = {} } + @statement_limit = statement_limit || DEFAULT_STATEMENT_LIMIT end def each(&block) @@ -26,7 +29,7 @@ module ActiveRecord end def []=(sql, stmt) - while @max <= cache.size + while @statement_limit <= cache.size dealloc(cache.shift.last) end cache[sql] = stmt @@ -46,13 +49,13 @@ module ActiveRecord private - def cache - @cache[Process.pid] - end + def cache + @cache[Process.pid] + end - def dealloc(stmt) - raise NotImplementedError - end + def dealloc(stmt) + raise NotImplementedError + end end end end |