<commit_before>defmodule RemoteRetro.Emails do
  import Bamboo.Email, except: [from: 2]
  import Ecto.Query
  alias RemoteRetro.Repo

  def action_items_email(retro_id) do
    new_email(
      to: "<EMAIL>",
      from: "<EMAIL>",
      subject: "Action items from Retro",
      text_body: text_retro_action_items(retro_id),
      html_body: html_retro_action_items(retro_id)
    )
  end

  defp text_retro_action_items(retro_id) do
    retro_action_items(retro_id)
    |> Enum.join("\n")
  end

  defp html_retro_action_items(retro_id) do
    retro_action_items(retro_id)
    |> Enum.join("<br/>")
  end

  defp retro_action_items(retro_id) do
    q = from i in RemoteRetro.Idea, where: [category: "action-item", retro_id: ^retro_id]
    q
    |> Repo.all
    |> Enum.map(&(&1.body))
  end
end<commit_msg>Only hit the db once in Emails.action_items_email/1<commit_after>defmodule RemoteRetro.Emails do
  import Bamboo.Email, except: [from: 2]
  import Ecto.Query
  alias RemoteRetro.Repo

  def action_items_email(retro_id) do
    action_items = retro_action_items(retro_id)

    new_email(
      to: "<EMAIL>",
      from: "<EMAIL>",
      subject: "Action items from Retro",
      text_body: text_retro_action_items(action_items),
      html_body: html_retro_action_items(action_items)
    )
  end

  defp text_retro_action_items(action_items) do
    action_items
    |> Enum.join("\n")
  end

  defp html_retro_action_items(action_items) do
    action_items
    |> Enum.join("<br/>")
  end

  defp retro_action_items(retro_id) do
    q = from i in RemoteRetro.Idea, where: [category: "action-item", retro_id: ^retro_id]
    q
    |> Repo.all
    |> Enum.map(&(&1.body))
  end
end
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0029708853238265003, 'mean_word_length': 3.6136986301369864, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '5494320', 'n_tokens_mistral': 652, 'n_tokens_neox': 632, 'n_words': 127}