123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::StatementPool

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activerecord/lib/active_record/connection_adapters/statement_pool.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#compact_blank

Returns a new ::Array without the blank items.

#exclude?

The negative of the Enumerable#include?.

#excluding

Returns a copy of the enumerable excluding the specified elements.

#in_order_of

Returns a new ::Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

#including

Returns a new array that includes the passed elements.

#index_by

Convert an enumerable to a hash, using the block result as the key and the element as the value.

#index_with

Convert an enumerable to a hash, using the element as the key and the block result as the value.

#maximum

Calculates the maximum from the extracted elements.

#minimum

Calculates the minimum from the extracted elements.

#pick

Extract the given key from the first element in the enumerable.

#pluck

Extract the given key from each element in the enumerable.

#sole

Returns the sole item in the enumerable.

#without
#as_json

::ActiveSupport::EnumerableCoreExt::Constants - Included

Constructor Details

.new(statement_limit = nil) ⇒ StatementPool

[ GitHub ]

  
# 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)

[ GitHub ]

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

def [](key)
  cache[key]
end

#[]=(sql, stmt)

[ GitHub ]

  
# 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

#cache (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 58

def cache
  @cache[Process.pid]
end

#clear Also known as: #reset

[ GitHub ]

  
# 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

#dealloc(stmt) (private)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 62

def dealloc(stmt)
  raise NotImplementedError
end

#delete(key)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 52

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

#each(&block)

[ GitHub ]

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

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

#key?(key) ⇒ Boolean

[ GitHub ]

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

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

#length

[ GitHub ]

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

def length
  cache.length
end

#reset

Clear the pool without deallocating; this is only safe when we know the server has independently deallocated all statements (e.g. due to a reconnect, or a DISCARD ALL)

[ GitHub ]

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

def reset
  cache.clear
end