Sha256: 69ac848f57c73651f177f238f1572cab05c3c2594961eb62a732a84e88a5f6f7

Contents?: true

Size: 1.02 KB

Versions: 31

Compression:

Stored size: 1.02 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    class StatementPool # :nodoc:
      include Enumerable

      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)
        cache.each(&block)
      end

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

      def [](key)
        cache[key]
      end

      def length
        cache.length
      end

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

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

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

      private

      def cache
        @cache[Process.pid]
      end

      def dealloc(stmt)
        raise NotImplementedError
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.7.1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.7 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.6 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.6.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.5 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.5.rc2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.5.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.4 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.4.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.3 lib/active_record/connection_adapters/statement_pool.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.2.rc1 lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/statement_pool.rb