Class: ActiveRecord::ConnectionAdapters::StatementPool

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
activerecord/lib/active_record/connection_adapters/statement_pool.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_STATEMENT_LIMIT =
1000

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without

Constructor Details

#initialize(statement_limit = nil) ⇒ StatementPool


10
11
12
13
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 10

def initialize(statement_limit = nil)
  @cache = Hash.new { |h, pid| h[pid] = {} }
  @statement_limit = statement_limit || DEFAULT_STATEMENT_LIMIT
end

Instance Method Details

#[](key) ⇒ Object


23
24
25
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 23

def [](key)
  cache[key]
end

#[]=(sql, stmt) ⇒ Object


31
32
33
34
35
36
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 31

def []=(sql, stmt)
  while @statement_limit <= cache.size
    dealloc(cache.shift.last)
  end
  cache[sql] = stmt
end

#clearObject


38
39
40
41
42
43
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 38

def clear
  cache.each_value do |stmt|
    dealloc stmt
  end
  cache.clear
end

#delete(key) ⇒ Object


45
46
47
48
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 45

def delete(key)
  dealloc cache[key]
  cache.delete(key)
end

#each(&block) ⇒ Object


15
16
17
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 15

def each(&block)
  cache.each(&block)
end

#key?(key) ⇒ Boolean


19
20
21
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 19

def key?(key)
  cache.key?(key)
end

#lengthObject


27
28
29
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 27

def length
  cache.length
end