From ba87c1679e57ba28e91352b45574fab0141b0cbe Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 27 Apr 2024 19:49:24 -0400 Subject: [PATCH] Further improve only_tag filtering --- .../controllers/profile/tag_change_controller.ex | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/philomena_web/controllers/profile/tag_change_controller.ex b/lib/philomena_web/controllers/profile/tag_change_controller.ex index 21524d4b..6aaa4c3a 100644 --- a/lib/philomena_web/controllers/profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/profile/tag_change_controller.ex @@ -31,7 +31,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do # params.permit(:added, :only_tag) ... pagination_params = [added: conn.params["added"], only_tag: conn.params["only_tag"]] - |> Keyword.filter(fn {k, _v} -> Map.has_key?(conn.params, "#{k}") end) + |> Keyword.filter(fn {_k, v} -> not is_nil(v) and v != "" end) render(conn, "index.html", title: "Tag Changes for User `#{user.name}'", @@ -50,14 +50,16 @@ defmodule PhilomenaWeb.Profile.TagChangeController do defp added_filter(query, _params), do: query - defp only_tag_join(query, %{"only_tag" => only_tag}) when only_tag != "", - do: join(query, :inner, [tc], t in Tag, on: tc.tag_id == t.id) + defp only_tag_join(query, %{"only_tag" => only_tag}) + when is_binary(only_tag) and only_tag != "", + do: join(query, :inner, [tc], t in Tag, on: tc.tag_id == t.id) defp only_tag_join(query, _params), do: query - defp only_tag_filter(query, %{"only_tag" => only_tag}) when only_tag != "", - do: where(query, [_, _, t], t.name == ^only_tag) + defp only_tag_filter(query, %{"only_tag" => only_tag}) + when is_binary(only_tag) and only_tag != "", + do: where(query, [_, _, t], t.name == ^only_tag) defp only_tag_filter(query, _params), do: query