<commit_before>module LegacyTaxonomy
  class TaxonomyPublisher
    attr_reader :root_taxon

    def initialize(root_taxon)
      @root_taxon = root_taxon
    end

    def commit
      create_remote_taxon(root_taxon)
      commit_tree(root_taxon)
    end

  private

    def commit_tree(taxon)
      taxon.child_taxons.each do |sub_taxon|
        create_remote_taxon(sub_taxon, taxon)
        sub_taxon.tagged_pages.each do |taggable|
          tag_content(taggable['content_id'], sub_taxon)
        end
        commit_tree(sub_taxon)
      end
    end

    def create_remote_taxon(taxon, parent_taxon = nil)
      puts "#{taxon.title} => #{taxon.base_path}"
      Services.publishing_api.put_content(taxon.content_id, taxon_for_publishing_api(taxon))
      Services.publishing_api.publish(taxon.content_id)

      return unless parent_taxon # rubocop
      Services.publishing_api.patch_links(taxon.content_id, links: { parent_taxons: [parent_taxon.content_id] })
    end

    def tag_content(taggable_content_id, taxon)
      puts " - Tagging #{base_path_for_content_id(taggable_content_id)}"

      links = Services.publishing_api.get_links(taggable_content_id)
      previous_version = links['version'] || 0
      taxons = links.dig('links', 'taxons') || []
      taxons << taxon.content_id
      Services.publishing_api.patch_links(taggable_content_id, links: { taxons: taxons }, previous_version: previous_version)
    rescue GdsApi::HTTPNotFound
      puts "404 Taggable Not Found"
    end

    def base_path_for_content_id(content_id)
      Services.publishing_api.get_content(content_id)['base_path']
    end

    def taxon_for_publishing_api(taxon)
      taxon_attrs = taxon.hash_for_publishing_api
      taxon_ = Taxon.new(taxon_attrs)
      Taxonomy::BuildTaxonPayload.call(taxon: taxon_)
    end
  end
end
<commit_msg>Dont refetch basepath for taggable content<commit_after>module LegacyTaxonomy
  class TaxonomyPublisher
    attr_reader :root_taxon

    def initialize(root_taxon)
      @root_taxon = root_taxon
    end

    def commit
      create_remote_taxon(root_taxon)
      commit_tree(root_taxon)
    end

  private

    def commit_tree(taxon)
      taxon.child_taxons.each do |sub_taxon|
        create_remote_taxon(sub_taxon, taxon)
        sub_taxon.tagged_pages.each do |taggable|
          tag_content(taggable, sub_taxon)
        end
        commit_tree(sub_taxon)
      end
    end

    def create_remote_taxon(taxon, parent_taxon = nil)
      puts "#{taxon.title} => #{taxon.base_path}"
      Services.publishing_api.put_content(taxon.content_id, taxon_for_publishing_api(taxon))
      Services.publishing_api.publish(taxon.content_id)

      return unless parent_taxon # rubocop
      Services.publishing_api.patch_links(taxon.content_id, links: { parent_taxons: [parent_taxon.content_id] })
    end

    def tag_content(taggable, taxon)
      puts " - Tagging #{taggable['link']}"

      links = Services.publishing_api.get_links(taggable['content_id'])
      previous_version = links['version'] || 0
      taxons = links.dig('links', 'taxons') || []
      taxons << taxon.content_id
      Services.publishing_api.patch_links(taggable['content_id'], links: { taxons: taxons }, previous_version: previous_version)
    rescue GdsApi::HTTPNotFound
      puts "404 Taggable Not Found"
    end

    def taxon_for_publishing_api(taxon)
      taxon_attrs = taxon.hash_for_publishing_api
      taxon_ = Taxon.new(taxon_attrs)
      Taxonomy::BuildTaxonPayload.call(taxon: taxon_)
    end
  end
end

{'fraction_non_alphanumeric': 0.08693181818181818, 'fraction_numerical': 0.0022727272727272726, 'mean_word_length': 3.5786736020806242, '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': '1882252', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1200, 'n_words': 195}