<commit_before>module Tire
  module Model
    module AsyncCallbacks

      extend ActiveSupport::Concern

      ID_CONVERSION = {
          'Moped::BSON::ObjectId' => :to_s
      }

      included do
        # Bind after save or create callback
        if self.respond_to? :after_commit
          after_commit :__async_tire_save_index

        elsif self.respond_to? :after_save
          after_save :__async_tire_save_index
        end

        # Bind before destroy callback
        if self.respond_to? :before_destroy
          before_destroy :__async_tire_delete_index
        end
      end

      def __async_tire_save_index
        __async_tire_callback :update
      end

      def __async_tire_delete_index
        __async_tire_callback :delete
      end

      def __async_tire_callback(type)
        case TireAsyncIndex.engine
          when :sidekiq
            TireAsyncIndex::Workers::SidekiqUpdateIndex.perform_async type, self.class.name, __async_tire_object_id

          when :resque
            Resque.enqueue TireAsyncIndex::Workers::ResqueUpdateIndex, type, self.class.name, __async_tire_object_id

          else
            case type
              when :update
                tire.update_index
              when :delete
                tire.index.remove self
            end
        end
      end

      def __async_tire_object_id<commit_msg>technical<commit_after>module Tire
  module Model
    module AsyncCallbacks

      ID_CONVERSION = {
          'Moped::BSON::ObjectId' => :to_s
      }

      def self.included(base)
        # Bind after save or create callback
        if base.respond_to? :after_commit
          base.send :after_commit, :async_tire_save_index

        elsif base.respond_to? :after_save
          base.send :after_save, :async_tire_save_index
        end

        # Bind before destroy callback
        if base.respond_to? :before_destroy
          base.send :before_destroy, :async_tire_delete_index
        end
      end

      private

      def async_tire_save_index
        async_tire_callback :update
      end

      def async_tire_delete_index
        async_tire_callback :delete
      end

      def async_tire_callback(type)
        case TireAsyncIndex.engine
          when :sidekiq
            TireAsyncIndex::Workers::SidekiqUpdateIndex.
              perform_async type, self.class.name, async_tire_object_id

          when :resque
            Resque.enqueue TireAsyncIndex::Workers::ResqueUpdateIndex,
              type, self.class.name, async_tire_object_id

          else
            case type
              when :update
                tire.update_index
              when :delete
                tire.index.remove self
            end
        end
      end

      def async_tire_object_id
{'fraction_non_alphanumeric': 0.0485331401666063, 'fraction_numerical': 0.0, 'mean_word_length': 1.9135021097046414, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3608187', 'n_tokens_mistral': 810, 'n_tokens_neox': 784, 'n_words': 168}