<commit_before>module SlavePools
  module ActiveRecordExtensions
    def self.included(base)
      base.cattr_accessor :connection_proxy

      base.send :include, InstanceMethods
      base.send :extend, ClassMethods
    end

    module InstanceMethods
      def reload(options = nil)
        self.connection_proxy.with_master { super }
      end
    end

    module ClassMethods
      # Make sure transactions always switch to the master
      def transaction(options = {}, &block)
        if self.connection.kind_of?(ConnectionProxy)
          super
        else
          self.connection_proxy.with_master { super }
        end
      end

      # Make sure caching always uses master connection
      def cache(&block)
        if ActiveRecord::Base.configurations.blank?
          yield
        else
          ActiveRecord::Base.connection.cache(&block)
        end
      end
    end
  end
end
<commit_msg>no need to separate InstanceMethods<commit_after>module SlavePools
  module ActiveRecordExtensions
    def self.included(base)
      base.send :extend, ClassMethods
      base.cattr_accessor :connection_proxy
    end

    def reload(options = nil)
      self.connection_proxy.with_master { super }
    end

    module ClassMethods
      # Make sure transactions always switch to the master
      def transaction(options = {}, &block)
        if self.connection.kind_of?(ConnectionProxy)
          super
        else
          self.connection_proxy.with_master { super }
        end
      end

      # Make sure caching always uses master connection
      def cache(&block)
        if ActiveRecord::Base.configurations.blank?
          yield
        else
          ActiveRecord::Base.connection.cache(&block)
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.059726962457337884, 'fraction_numerical': 0.0, 'mean_word_length': 2.2634508348794062, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6428703', 'n_tokens_mistral': 459, 'n_tokens_neox': 450, 'n_words': 126}