<commit_before>module FullTextSearch
  class ChangeMapper < Mapper
    class << self
      def redmine_mapper_class
        RedmineChangeMapper
      end

      def fts_mapper_class
        FtsChangeMapper
      end
    end
  end
  resolver.register(Change, ChangeMapper)

  class RedmineChangeMapper < RedmineMapper
    class << self
      def not_mapped(redmine_class)
        fts_targets =
          Target
            .where(source_type_id: Type[redmine_class].id)
            .select(:source_id)
        if fts_targets.exists?
          targets = redmine_class.where.not(id: fts_targets)
          last_source_id =
            fts_targets
              .order(source_id: :desc)
              .limit(1)
              .pluck(:source_id)
              .first
          if last_source_id
            targets = targets.where(id: (last_source_id + 1)..Float::INFINITY)
          end
          targets.order(id: :asc)
        else
          source_ids = redmine_class
            .joins(changeset: [:repository])
            .group("repositories.id, changes.path")
            .select("MAX(changes.id) as id")
          redmine_class.where(id: source_ids).order(id: :asc)
        end
      end
    end

    def upsert_fts_target(options={})
      case @record.action
      when "A", "M"
        changeset = @record.changeset
        repository = changeset.repository
        return if repository.nil?
        identifier = changeset.identifier
        entry = repository.entry(@record.path, identifier)
        return if entry.nil?<commit_msg>change: simplify not mapped check<commit_after>module FullTextSearch
  class ChangeMapper < Mapper
    class << self
      def redmine_mapper_class
        RedmineChangeMapper
      end

      def fts_mapper_class
        FtsChangeMapper
      end
    end
  end
  resolver.register(Change, ChangeMapper)

  class RedmineChangeMapper < RedmineMapper
    class << self
      def not_mapped(redmine_class)
        source_ids = redmine_class
                       .joins(changeset: [:repository])
                       .group("repositories.id, changes.path")
                       .select("MAX(changes.id) as id")
        super.where(id: source_ids)
      end
    end

    def upsert_fts_target(options={})
      case @record.action
      when "A", "M"
        changeset = @record.changeset
        repository = changeset.repository
        return if repository.nil?
        identifier = changeset.identifier
        entry = repository.entry(@record.path, identifier)
        return if entry.nil?
{'fraction_non_alphanumeric': 0.08007889546351085, 'fraction_numerical': 0.0007889546351084812, 'mean_word_length': 1.9940968122786304, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2255515', 'n_tokens_mistral': 733, 'n_tokens_neox': 711, 'n_words': 154}