<commit_before>module RedirectDestinationHelper
  def redirect_destination_select_options
    {
      "Other" => ["/service-manual", "/service-manual/service-standard"],
      "Topics" => topic_select_options,
      "Guides" => guide_select_options,
    }
  end

private

  def guide_select_options
    Guide.live.order(:slug).pluck(:slug)
  end

  def topic_select_options
    Topic.order(:path)
      .flat_map { |topic| paths_for_topic_and_its_sections(topic) }
  end

  def paths_for_topic_and_its_sections(topic)
    topic_sections = topic.topic_sections.order(:title).where("title <> ''").map do |section|
      ["#{topic.path} → #{section.title}", "#{topic.path}##{section.title.parameterize}"]
    end
<commit_msg>Eager load topic sections to avoid N+1 queries<commit_after>module RedirectDestinationHelper
  def redirect_destination_select_options
    {
      "Other" => ["/service-manual", "/service-manual/service-standard"],
      "Topics" => topic_select_options,
      "Guides" => guide_select_options,
    }
  end

private

  def guide_select_options
    Guide.live.order(:slug).pluck(:slug)
  end

  def topic_select_options
    Topic.includes(:topic_sections).order(:path)
      .flat_map { |topic| paths_for_topic_and_its_sections(topic) }
  end

  def paths_for_topic_and_its_sections(topic)
    topic_sections = topic.topic_sections.order(:title).where("title <> ''").map do |section|
      ["#{topic.path} → #{section.title}", "#{topic.path}##{section.title.parameterize}"]
    end

{'fraction_non_alphanumeric': 0.13506320691949433, 'fraction_numerical': 0.0006653359946773121, 'mean_word_length': 4.3144876325088335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3736496', 'n_tokens_mistral': 491, 'n_tokens_neox': 484, 'n_words': 79}