Compare commits

..

No commits in common. "af349b073ae63c2c91eaadded726a68c6c745d97" and "90ed27939b3fc3a282117610e31f204a1f772386" have entirely different histories.

17 changed files with 60 additions and 41 deletions

View file

@ -224,7 +224,8 @@ defp hell_thread_mentions(users) do
|> Enum.reduce([users[:user]], fn group, acc ->
acc ++ Enum.take(users[group], 5)
end)
|> Enum.map_join(", ", &"@#{&1.nickname}")
|> Enum.map(&"@#{&1.nickname}")
|> Enum.join(", ")
Cachex.put(:user_cache, "hell_thread_mentions", cached)
cached

View file

@ -8,7 +8,6 @@ defmodule Mix.Tasks.Pleroma.Activity do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Pagination
alias Pleroma.Search.DatabaseSearch
require Logger
import Mix.Pleroma
import Ecto.Query
@ -25,25 +24,11 @@ def run(["delete_by_keyword", user, keyword | _rest]) do
start_pleroma()
u = User.get_by_nickname(user)
index_type =
cond do
Pleroma.Config.get([:database, :rum_enabled]) -> :rum
Pleroma.Config.get([:database, :pgroonga_enabled]) -> :pgroonga
true -> :gin
end
search_function =
if :persistent_term.get({Pleroma.Repo, :postgres_version}) >= 11 do
:websearch
else
:plain
end
Activity
|> Activity.with_preloaded_object()
|> Activity.restrict_deactivated_users()
|> Activity.Queries.by_author(u)
|> DatabaseSearch.query_with(index_type, keyword, search_function)
|> query_with(keyword)
|> Pagination.fetch_paginated(
%{"offset" => 0, "limit" => 20, "skip_order" => false},
:offset
@ -52,4 +37,22 @@ def run(["delete_by_keyword", user, keyword | _rest]) do
|> Enum.count()
|> IO.puts()
end
defp query_with(q, search_query) do
%{rows: [[tsc]]} =
Ecto.Adapters.SQL.query!(
Pleroma.Repo,
"select current_setting('default_text_search_config')::regconfig::oid;"
)
from([a, o] in q,
where:
fragment(
"to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
^tsc,
o.data,
^search_query
)
)
end
end

View file

@ -303,7 +303,7 @@ def run(["gen" | rest]) do
else
shell_error(
"The task would have overwritten the following files:\n" <>
Enum.map_join(will_overwrite, "", &"- #{&1}\n") <>
(Enum.map(will_overwrite, &"- #{&1}\n") |> Enum.join("")) <>
"Rerun with `--force` to overwrite them."
)
end

View file

@ -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_join("\n", fn
|> Enum.map(fn
%{id: id} ->
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
"<li><a href=\"#{status_url}\">#{status_url}</li>"
@ -54,6 +54,7 @@ def report(to, reporter, account, statuses, comment) do
id when is_binary(id) ->
"<li><a href=\"#{id}\">#{id}</li>"
end)
|> Enum.join("\n")
"""
<p> Statuses:

View file

@ -134,9 +134,10 @@ defp update_emojis(emojis) do
|> hd()
|> String.trim()
|> String.split()
|> Enum.map_join(fn codepoint ->
|> Enum.map(fn codepoint ->
<<String.to_integer(codepoint, 16)::utf8>>
end)
|> Enum.join()
end)
|> Enum.uniq()

View file

@ -207,7 +207,8 @@ def compose_regex(%User{} = user, format) do
def compose_regex([_ | _] = filters, format) do
phrases =
filters
|> Enum.map_join("|", & &1.phrase)
|> Enum.map(& &1.phrase)
|> Enum.join("|")
case format do
:postgres ->

View file

@ -556,12 +556,14 @@ def get_log_entry_message(%ModerationLog{
defp nicknames_to_string(nicknames) do
nicknames
|> Enum.map_join(", ", &"@#{&1}")
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
end
defp users_to_nicknames_string(users) do
users
|> Enum.map_join(", ", &"@#{&1["nickname"]}")
|> Enum.map(&"@#{&1["nickname"]}")
|> Enum.join(", ")
end
defp subject_actor_nickname(%ModerationLog{data: data}, prefix_msg, postfix_msg \\ "") do

View file

@ -78,7 +78,7 @@ def restrict_public(q) do
)
end
def query_with(q, :gin, search_query, :plain) do
defp query_with(q, :gin, search_query, :plain) do
%{rows: [[tsc]]} =
Ecto.Adapters.SQL.query!(
Pleroma.Repo,
@ -96,7 +96,7 @@ def query_with(q, :gin, search_query, :plain) do
)
end
def query_with(q, :gin, search_query, :websearch) do
defp query_with(q, :gin, search_query, :websearch) do
%{rows: [[tsc]]} =
Ecto.Adapters.SQL.query!(
Pleroma.Repo,
@ -114,7 +114,7 @@ def query_with(q, :gin, search_query, :websearch) do
)
end
def query_with(q, :rum, search_query, :plain) do
defp query_with(q, :rum, search_query, :plain) do
from([a, o] in q,
where:
fragment(
@ -126,7 +126,7 @@ def query_with(q, :rum, search_query, :plain) do
)
end
def query_with(q, :rum, search_query, :websearch) do
defp query_with(q, :rum, search_query, :websearch) do
from([a, o] in q,
where:
fragment(
@ -138,7 +138,7 @@ def query_with(q, :rum, search_query, :websearch) do
)
end
def query_with(q, :pgroonga, search_query, _) do
defp query_with(q, :pgroonga, search_query, _) do
# PGroonga only supports PostgreSQL version 11 or newer
from([a, o] in q,
where:

View file

@ -134,7 +134,8 @@ defp to_tsquery(query_string) do
|> String.replace(~r/[!-\/|@|[-`|{-~|:-?]+/, " ")
|> String.trim()
|> String.split()
|> Enum.map_join(" | ", &(&1 <> ":*"))
|> Enum.map(&(&1 <> ":*"))
|> Enum.join(" | ")
end
# Considers nickname match, localized nickname match, name match; preferences nickname match

View file

@ -30,7 +30,7 @@ def call(conn, errors) do
conn
|> put_status(:bad_request)
|> json(%{
error: errors |> Enum.map_join(" ", &message/1),
error: errors |> Enum.map(&message/1) |> Enum.join(" "),
errors: errors |> Enum.map(&render_error/1)
})
end

View file

@ -167,7 +167,8 @@ defp preprocess_uri_query(query) do
defp joined_tag(tags) do
tags
|> Enum.map_join(fn tag -> String.capitalize(tag) end)
|> Enum.map(fn tag -> String.capitalize(tag) end)
|> Enum.join()
end
defp with_fallback(f, fallback \\ []) do

View file

@ -15,7 +15,8 @@ def build_static_tags(params) do
params
|> parser.build_tags()
|> Enum.map(&to_tag/1)
|> Enum.map_join(&HTML.safe_to_string/1)
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.join()
acc <> rendered_html
end)
@ -34,7 +35,8 @@ def build_tags(params) do
params
|> parser.build_tags()
|> Enum.map(&to_tag/1)
|> Enum.map_join(&HTML.safe_to_string/1)
|> Enum.map(&HTML.safe_to_string/1)
|> Enum.join()
acc <> rendered_html
end)

View file

@ -244,7 +244,8 @@ defp attach_selected_params(input, %{conn_params: conn_params, opts: plug_opts})
plug_opts
|> Keyword.get(:params, [])
|> Enum.sort()
|> Enum.map_join(":", &Map.get(conn_params, &1, ""))
|> Enum.map(&Map.get(conn_params, &1, ""))
|> Enum.join(":")
[input, params_string]
|> Enum.join(":")

View file

@ -94,7 +94,8 @@ test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject
users =
[subject1.nickname, subject2.nickname]
|> Enum.map_join(", ", &"@#{&1}")
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["foo", "bar"] |> Enum.join(", ")
@ -114,7 +115,8 @@ test "logging user untagged by admin", %{admin: admin, subject1: subject1, subje
users =
[subject1.nickname, subject2.nickname]
|> Enum.map_join(", ", &"@#{&1}")
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["foo", "bar"] |> Enum.join(", ")

View file

@ -122,7 +122,8 @@ test "it appends specified tags to users with specified nicknames", %{
users =
[user1.nickname, user2.nickname]
|> Enum.map_join(", ", &"@#{&1}")
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["foo", "bar"] |> Enum.join(", ")
@ -167,7 +168,8 @@ test "it removes specified tags from users with specified nicknames", %{
users =
[user1.nickname, user2.nickname]
|> Enum.map_join(", ", &"@#{&1}")
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["x", "z"] |> Enum.join(", ")

View file

@ -247,7 +247,8 @@ test "Removes a conversation", %{user: user_one, conn: conn} do
defp create_direct_message(sender, recips) do
hellos =
recips
|> Enum.map_join(", ", fn s -> "@#{s.nickname}" end)
|> Enum.map(fn s -> "@#{s.nickname}" end)
|> Enum.join(", ")
CommonAPI.post(sender, %{
status: "Hi #{hellos}!",

View file

@ -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_join(0..name_limit, fn _ -> "x" end)
long_value = Enum.map_join(0..value_limit, fn _ -> "x" end)
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
fields = [%{name: "foo", value: long_value}]