From aba4e6ea608a60f4c31960f1f7512b4e8e75b4c2 Mon Sep 17 00:00:00 2001 From: itepechi <72330683+itepechi@users.noreply.github.com> Date: Sun, 6 Aug 2023 22:17:17 +0900 Subject: [PATCH] Replace map |> join with map_join --- benchmarks/load_testing/activities.ex | 3 +-- lib/mix/tasks/pleroma/instance.ex | 2 +- lib/pleroma/emails/admin_email.ex | 3 +-- lib/pleroma/emoji.ex | 3 +-- lib/pleroma/filter.ex | 3 +-- lib/pleroma/moderation_log.ex | 6 ++---- lib/pleroma/user/search.ex | 3 +-- lib/pleroma/web/api_spec/render_error.ex | 2 +- .../web/mastodon_api/controllers/search_controller.ex | 3 +-- lib/pleroma/web/metadata.ex | 6 ++---- lib/pleroma/web/plugs/rate_limiter.ex | 3 +-- test/pleroma/moderation_log_test.exs | 6 ++---- .../web/admin_api/controllers/admin_api_controller_test.exs | 6 ++---- .../controllers/conversation_controller_test.exs | 3 +-- test/pleroma/web/mastodon_api/update_credentials_test.exs | 4 ++-- 15 files changed, 20 insertions(+), 36 deletions(-) diff --git a/benchmarks/load_testing/activities.ex b/benchmarks/load_testing/activities.ex index 7f262d228..dc505c045 100644 --- a/benchmarks/load_testing/activities.ex +++ b/benchmarks/load_testing/activities.ex @@ -224,8 +224,7 @@ defp hell_thread_mentions(users) do |> Enum.reduce([users[:user]], fn group, acc -> acc ++ Enum.take(users[group], 5) end) - |> Enum.map(&"@#{&1.nickname}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1.nickname}") Cachex.put(:user_cache, "hell_thread_mentions", cached) cached diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 54c601727..2b0da10cc 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -303,7 +303,7 @@ def run(["gen" | rest]) do else shell_error( "The task would have overwritten the following files:\n" <> - (Enum.map(will_overwrite, &"- #{&1}\n") |> Enum.join("")) <> + Enum.map_join(will_overwrite, "", &"- #{&1}\n") <> "Rerun with `--force` to overwrite them." ) end diff --git a/lib/pleroma/emails/admin_email.ex b/lib/pleroma/emails/admin_email.ex index 88bc78aec..d44e182e7 100644 --- a/lib/pleroma/emails/admin_email.ex +++ b/lib/pleroma/emails/admin_email.ex @@ -43,7 +43,7 @@ def report(to, reporter, account, statuses, comment) do if is_list(statuses) && length(statuses) > 0 do statuses_list_html = statuses - |> Enum.map(fn + |> Enum.map_join("\n", fn %{id: id} -> status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id) "
  • #{status_url}
  • " @@ -54,7 +54,6 @@ def report(to, reporter, account, statuses, comment) do id when is_binary(id) -> "
  • #{id}
  • " end) - |> Enum.join("\n") """

    Statuses: diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 933f4275a..d320b9a71 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -134,10 +134,9 @@ defp update_emojis(emojis) do |> hd() |> String.trim() |> String.split() - |> Enum.map(fn codepoint -> + |> Enum.map_join(fn codepoint -> <> end) - |> Enum.join() end) |> Enum.uniq() diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index 82b9caf9b..8e58bacb9 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -207,8 +207,7 @@ def compose_regex(%User{} = user, format) do def compose_regex([_ | _] = filters, format) do phrases = filters - |> Enum.map(& &1.phrase) - |> Enum.join("|") + |> Enum.map_join("|", & &1.phrase) case format do :postgres -> diff --git a/lib/pleroma/moderation_log.ex b/lib/pleroma/moderation_log.ex index b94d53913..2e50acb26 100644 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@ -556,14 +556,12 @@ def get_log_entry_message(%ModerationLog{ defp nicknames_to_string(nicknames) do nicknames - |> Enum.map(&"@#{&1}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1}") end defp users_to_nicknames_string(users) do users - |> Enum.map(&"@#{&1["nickname"]}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1["nickname"]}") end defp subject_actor_nickname(%ModerationLog{data: data}, prefix_msg, postfix_msg \\ "") do diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex index ddce51775..08375bdb3 100644 --- a/lib/pleroma/user/search.ex +++ b/lib/pleroma/user/search.ex @@ -134,8 +134,7 @@ defp to_tsquery(query_string) do |> String.replace(~r/[!-\/|@|[-`|{-~|:-?]+/, " ") |> String.trim() |> String.split() - |> Enum.map(&(&1 <> ":*")) - |> Enum.join(" | ") + |> Enum.map_join(" | ", &(&1 <> ":*")) end # Considers nickname match, localized nickname match, name match; preferences nickname match diff --git a/lib/pleroma/web/api_spec/render_error.ex b/lib/pleroma/web/api_spec/render_error.ex index e501a6be4..7feec4fd3 100644 --- a/lib/pleroma/web/api_spec/render_error.ex +++ b/lib/pleroma/web/api_spec/render_error.ex @@ -30,7 +30,7 @@ def call(conn, errors) do conn |> put_status(:bad_request) |> json(%{ - error: errors |> Enum.map(&message/1) |> Enum.join(" "), + error: errors |> Enum.map_join(" ", &message/1), errors: errors |> Enum.map(&render_error/1) }) end diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex index bd12069c1..94fbdceca 100644 --- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex @@ -167,8 +167,7 @@ defp preprocess_uri_query(query) do defp joined_tag(tags) do tags - |> Enum.map(fn tag -> String.capitalize(tag) end) - |> Enum.join() + |> Enum.map_join(fn tag -> String.capitalize(tag) end) end defp with_fallback(f, fallback \\ []) do diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 48801b588..b7470ed10 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -15,8 +15,7 @@ def build_static_tags(params) do params |> parser.build_tags() |> Enum.map(&to_tag/1) - |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join() + |> Enum.map_join(&HTML.safe_to_string/1) acc <> rendered_html end) @@ -35,8 +34,7 @@ def build_tags(params) do params |> parser.build_tags() |> Enum.map(&to_tag/1) - |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join() + |> Enum.map_join(&HTML.safe_to_string/1) acc <> rendered_html end) diff --git a/lib/pleroma/web/plugs/rate_limiter.ex b/lib/pleroma/web/plugs/rate_limiter.ex index 3c82654b4..59bb1fef1 100644 --- a/lib/pleroma/web/plugs/rate_limiter.ex +++ b/lib/pleroma/web/plugs/rate_limiter.ex @@ -244,8 +244,7 @@ defp attach_selected_params(input, %{conn_params: conn_params, opts: plug_opts}) plug_opts |> Keyword.get(:params, []) |> Enum.sort() - |> Enum.map(&Map.get(conn_params, &1, "")) - |> Enum.join(":") + |> Enum.map_join(":", &Map.get(conn_params, &1, "")) [input, params_string] |> Enum.join(":") diff --git a/test/pleroma/moderation_log_test.exs b/test/pleroma/moderation_log_test.exs index 607301815..e93786a3e 100644 --- a/test/pleroma/moderation_log_test.exs +++ b/test/pleroma/moderation_log_test.exs @@ -94,8 +94,7 @@ test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject users = [subject1.nickname, subject2.nickname] - |> Enum.map(&"@#{&1}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1}") tags = ["foo", "bar"] |> Enum.join(", ") @@ -115,8 +114,7 @@ test "logging user untagged by admin", %{admin: admin, subject1: subject1, subje users = [subject1.nickname, subject2.nickname] - |> Enum.map(&"@#{&1}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1}") tags = ["foo", "bar"] |> Enum.join(", ") diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs index e423b2311..cce812805 100644 --- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs @@ -122,8 +122,7 @@ test "it appends specified tags to users with specified nicknames", %{ users = [user1.nickname, user2.nickname] - |> Enum.map(&"@#{&1}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1}") tags = ["foo", "bar"] |> Enum.join(", ") @@ -168,8 +167,7 @@ test "it removes specified tags from users with specified nicknames", %{ users = [user1.nickname, user2.nickname] - |> Enum.map(&"@#{&1}") - |> Enum.join(", ") + |> Enum.map_join(", ", &"@#{&1}") tags = ["x", "z"] |> Enum.join(", ") diff --git a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs index 00797a9ea..a9ad5d190 100644 --- a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs @@ -247,8 +247,7 @@ test "Removes a conversation", %{user: user_one, conn: conn} do defp create_direct_message(sender, recips) do hellos = recips - |> Enum.map(fn s -> "@#{s.nickname}" end) - |> Enum.join(", ") + |> Enum.map_join(", ", fn s -> "@#{s.nickname}" end) CommonAPI.post(sender, %{ status: "Hi #{hellos}!", diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index 70566f5d0..8a5115821 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -630,8 +630,8 @@ test "update fields when invalid request", %{conn: conn} do name_limit = Pleroma.Config.get([:instance, :account_field_name_length]) value_limit = Pleroma.Config.get([:instance, :account_field_value_length]) - long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join() - long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join() + long_name = Enum.map_join(0..name_limit, fn _ -> "x" end) + long_value = Enum.map_join(0..value_limit, fn _ -> "x" end) fields = [%{name: "foo", value: long_value}]