<commit_before>module ActiveRecord
  class Base
    class << self
      # This clobbers the DB Charmer wrapping of relation and does the same thing except
      # it leaves connection resolution to runtime rather than assigning an instance variable
      def relation_with_db_charmer(*args, &block)
        relation_without_db_charmer(*args, &block).tap do |rel|
          begin
            rel.db_charmer_connection = @connection
          rescue StandardError => e
            base = self
            rel.define_singleton_method(:db_charmer_connection) do
              base.connection
            end
          end
          rel.db_charmer_enable_slaves = self.db_charmer_slaves.any?
          rel.db_charmer_connection_is_forced = !db_charmer_top_level_connection?
        end
      end
      alias relation relation_with_db_charmer
    end
  end<commit_msg>Changed our approach to handling db-charmer relations. It was causing MySQL locks during parallel testing.<commit_after>module ActiveRecord
  class Base
    class << self

      def relation_with_wraith_charmed(*args, &block)
        begin
          relation_without_wraith_charmed(*args, &block)
        rescue StandardError => e
          # This leaves connection resolution for db_charmer to runtime rather than assigning an
          # instance variable
          base = self
          rel = relation_without_db_charmer
          rel.define_singleton_method(:db_charmer_connection) do
            base.connection
          end
          rel.db_charmer_enable_slaves = self.db_charmer_slaves.any?
          rel.db_charmer_connection_is_forced = !db_charmer_top_level_connection?
          rel
        end
      end
      alias_method_chain :relation, :wraith_charmed
    end
  end
{'fraction_non_alphanumeric': 0.046418338108882524, 'fraction_numerical': 0.0, 'mean_word_length': 2.5272727272727273, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '7183564', 'n_tokens_mistral': 472, 'n_tokens_neox': 467, 'n_words': 125}