<commit_before>defmodule Ello.V2.PostController do
  use Ello.V2.Web, :controller
  alias Ello.Core.{Content, Content.Post}
  alias Ello.Events
  alias Ello.Events.CountPostView

  def show(conn, params) do
    with %Post{} = post <- load_post(conn, params),
         true           <- owned_by_user(post, params) do
      track_post_view(conn, post)
      render(conn, post: post)
    else
      _ -> send_resp(conn, 404, "")
    end
  end

  defp load_post(conn, %{"id" => id_or_slug}) do
    Content.post(id_or_slug,
      conn.assigns[:current_user],
      conn.assigns[:allow_nsfw],
      conn.assigns[:allow_nudity]
    )
  end

  defp track_post_view(%{assigns: assigns} = conn, post) do
    current_user_id = case assigns[:current_user] do
      %{id: id} -> id
      _ -> nil
    end

    event = %CountPostView{
      post_ids: [post.id],
      current_user_id: current_user_id,
      stream_kind: "post",
    }
    Ello.Events.publish(event)
  end

  defp owned_by_user(post, %{"user_id" => "~" <> username}),
    do: post.author.username == username
  defp owned_by_user(post, %{"user_id" => user_id}),
    do: "#{post.author.id}" == user_id
  defp owned_by_user(_, _), do: true

end<commit_msg>fix warnings<commit_after>defmodule Ello.V2.PostController do
  use Ello.V2.Web, :controller
  alias Ello.Core.{Content, Content.Post}
  alias Ello.Events
  alias Ello.Events.CountPostView

  def show(conn, params) do
    with %Post{} = post <- load_post(conn, params),
         true           <- owned_by_user(post, params) do
      track_post_view(conn, post)
      render(conn, post: post)
    else
      _ -> send_resp(conn, 404, "")
    end
  end

  defp load_post(conn, %{"id" => id_or_slug}) do
    Content.post(id_or_slug,
      conn.assigns[:current_user],
      conn.assigns[:allow_nsfw],
      conn.assigns[:allow_nudity]
    )
  end

  defp track_post_view(%{assigns: assigns}, post) do
    current_user_id = case assigns[:current_user] do
      %{id: id} -> id
      _ -> nil
    end

    event = %CountPostView{
      post_ids: [post.id],
      current_user_id: current_user_id,
      stream_kind: "post",
    }
    Events.publish(event)
  end

  defp owned_by_user(post, %{"user_id" => "~" <> username}),
    do: post.author.username == username
  defp owned_by_user(post, %{"user_id" => user_id}),
    do: "#{post.author.id}" == user_id
  defp owned_by_user(_, _), do: true

end
{'fraction_non_alphanumeric': 0.136609745939192, 'fraction_numerical': 0.004164931278633903, 'mean_word_length': 2.9834162520729683, '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': '4324693', 'n_tokens_mistral': 898, 'n_tokens_neox': 873, 'n_words': 179}