<commit_before>module ElasticRecord
  class Index
    module Deferred
      class DeferredConnection
        class DeferredAction < Struct.new(:method, :args, :block)
          def run(index)
            index.send(method, *args, &block)
          end
        end

        attr_accessor :index
        attr_accessor :deferred_actions
        attr_accessor :writes_made

        def initialize(index)
          self.index = index
          reset!
        end

        def reset!
          if writes_made
            begin
              index.disable_deferring!
              index.reset
            ensure
              index.enable_deferring!
            end
          end
          self.deferred_actions = []
          self.writes_made = false
        end
<commit_msg>Deferred performance improvement: Use delete_by_query rather than reset<commit_after>module ElasticRecord
  class Index
    module Deferred
      class DeferredConnection
        class DeferredAction < Struct.new(:method, :args, :block)
          def run(index)
            index.send(method, *args, &block)
          end
        end

        attr_accessor :index
        attr_accessor :deferred_actions
        attr_accessor :writes_made

        def initialize(index)
          self.index = index
          reset!
        end

        def reset!
          if writes_made
            begin
              index.disable_deferring!
              index.delete_by_query match_all: {}
            ensure
              index.enable_deferring!
            end
          end
          self.deferred_actions = []
          self.writes_made = false
        end

{'fraction_non_alphanumeric': 0.05308641975308642, 'fraction_numerical': 0.0, 'mean_word_length': 1.5170807453416149, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4874923', 'n_tokens_mistral': 417, 'n_tokens_neox': 410, 'n_words': 102}