<commit_before># frozen_string_literal: true

module Eve
  class TypesImporter
    attr_reader :page, :esi

    def initialize(page = 1)
      @page = page
      @esi = EveOnline::ESI::UniverseTypes.new(page: @page)
    end

    def import
      etag = Etag.find_or_initialize_by(url: esi.url)

      esi.etag = etag.etag

      return if esi.not_modified?

      import_types

      import_other_pages

      etag.update!(etag: esi.etag)
    end

    private

    def import_types
      esi.universe_type_ids.each do |type_id|
        if !Eve::Type.where(type_id: type_id).exists?
          Eve::TypeImporterWorker.perform_async(type_id)
        end
      end
    end

    def import_other_pages
      return if page != 1

      (2..esi.total_pages).each do |next_page|
        Eve::TypesImporterWorker.perform_async(next_page)
      end
    end
  end
end<commit_msg>Make sure that we run Types importer with total pages more than 1<commit_after># frozen_string_literal: true

module Eve
  class TypesImporter
    attr_reader :page, :esi

    def initialize(page = 1)
      @page = page
      @esi = EveOnline::ESI::UniverseTypes.new(page: @page)
    end

    def import
      etag = Etag.find_or_initialize_by(url: esi.url)

      esi.etag = etag.etag

      return if esi.not_modified?

      import_types

      import_other_pages

      etag.update!(etag: esi.etag)
    end

    private

    def import_types
      esi.universe_type_ids.each do |type_id|
        if !Eve::Type.where(type_id: type_id).exists?
          Eve::TypeImporterWorker.perform_async(type_id)
        end
      end
    end

    def import_other_pages
      return if page != 1 || esi.total_pages == 1

      (2..esi.total_pages).each do |next_page|
        Eve::TypesImporterWorker.perform_async(next_page)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08443708609271523, 'fraction_numerical': 0.004415011037527594, 'mean_word_length': 2.4731800766283527, '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': '3292637', 'n_tokens_mistral': 641, 'n_tokens_neox': 610, 'n_words': 135}