<commit_before>begin
  require 'spec'
rescue LoadError
  require 'rubygems'
  gem 'rspec'
  require 'spec'
end

require 'drb'
require 'digest/sha1'

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
$LOAD_PATH.unshift File.dirname(__FILE__)

require 'rubyrep'
require 'connection_extender_interface_spec'



module RR::ConnectionExtenders
  
  class << self
    alias_method :db_connect_without_cache, :db_connect unless method_defined?(:db_connect_without_cache)
    
    @@use_db_connection_cache = true
    
    # For faster spec runs, overwrite db_connect to use connection caching 
    def db_connect(config)
      config_dump = Marshal.dump config.reject {|key, | [:proxy_host, :proxy_port].include? key}
      config_checksum = Digest::SHA1.hexdigest(config_dump)
      @@db_connection_cache ||= {}
      cached_db_connection = @@db_connection_cache[config_checksum]
      if @@use_db_connection_cache and cached_db_connection and cached_db_connection.active?
        cached_db_connection
      else
        db_connection = db_connect_without_cache config
        @@db_connection_cache[config_checksum] = db_connection
        db_connection
      end
    end
    
    # If status == true: enable the cache. If status == false: don' use cache
    # Returns the old connection caching status
    def use_db_connection_cache(status)
      old_status, @@use_db_connection_cache = @@use_db_connection_cache, status
      old_status
    end
    
    # Free up all cached connections
    def clear_db_connection_cache
      @@db_connection_cache = {}
    end
  end<commit_msg>Fixed bug in spec_helper database connection caching code<commit_after>begin
  require 'spec'
rescue LoadError
  require 'rubygems'
  gem 'rspec'
  require 'spec'
end

require 'drb'
require 'digest/sha1'

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
$LOAD_PATH.unshift File.dirname(__FILE__)

require 'rubyrep'
require 'connection_extender_interface_spec'



module RR::ConnectionExtenders
  
  class << self
    alias_method :db_connect_without_cache, :db_connect unless method_defined?(:db_connect_without_cache)
    
    @@use_db_connection_cache = true
    
    # For faster spec runs, overwrite db_connect to use connection caching 
    def db_connect(config)
      config_dump = Marshal.dump config.reject {|key, | [:proxy_host, :proxy_port].include? key}
      config_checksum = Digest::SHA1.hexdigest(config_dump)
      @@db_connection_cache ||= {}
      cached_db_connection = @@db_connection_cache[config_checksum]
      if @@use_db_connection_cache and cached_db_connection and cached_db_connection.active?
        cached_db_connection
      else
        db_connection = db_connect_without_cache config
        @@db_connection_cache[config_checksum] = db_connection if @@use_db_connection_cache
        db_connection
      end
    end
    
    # If status == true: enable the cache. If status == false: don' use cache
    # Returns the old connection caching status
    def use_db_connection_cache(status)
      old_status, @@use_db_connection_cache = @@use_db_connection_cache, status
      old_status
    end
    
    # Free up all cached connections
    def clear_db_connection_cache
      @@db_connection_cache = {}
    end
  end
{'fraction_non_alphanumeric': 0.07859993859379798, 'fraction_numerical': 0.0012281240405280934, 'mean_word_length': 3.9066265060240966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2928781', 'n_tokens_mistral': 1019, 'n_tokens_neox': 978, 'n_words': 232}