Merge branch 'merge-upstream' into 'develop'
Merge Pleroma upstream See merge request soapbox-pub/soapbox!75
This commit is contained in:
commit
0e2533c17c
4 changed files with 14 additions and 77 deletions
|
@ -149,8 +149,6 @@
|
|||
]
|
||||
|
||||
# Configures Elixir's Logger
|
||||
config :logger, truncate: 65536
|
||||
|
||||
config :logger, :console,
|
||||
level: :debug,
|
||||
format: "\n$time $metadata[$level] $message\n",
|
||||
|
@ -865,13 +863,6 @@
|
|||
{Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy, [max_running: 5, max_waiting: 5]}
|
||||
]
|
||||
|
||||
config :pleroma, :telemetry,
|
||||
slow_queries_logging: [
|
||||
enabled: false,
|
||||
min_duration: 500_000,
|
||||
exclude_sources: [nil, "oban_jobs"]
|
||||
]
|
||||
|
||||
import_config "soapbox.exs"
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
|
|
|
@ -12,16 +12,10 @@ defmodule Pleroma.Telemetry.Logger do
|
|||
[:pleroma, :connection_pool, :reclaim, :stop],
|
||||
[:pleroma, :connection_pool, :provision_failure],
|
||||
[:pleroma, :connection_pool, :client, :dead],
|
||||
[:pleroma, :connection_pool, :client, :add],
|
||||
[:pleroma, :repo, :query]
|
||||
[:pleroma, :connection_pool, :client, :add]
|
||||
]
|
||||
def attach do
|
||||
:telemetry.attach_many(
|
||||
"pleroma-logger",
|
||||
@events,
|
||||
&Pleroma.Telemetry.Logger.handle_event/4,
|
||||
[]
|
||||
)
|
||||
:telemetry.attach_many("pleroma-logger", @events, &handle_event/4, [])
|
||||
end
|
||||
|
||||
# Passing anonymous functions instead of strings to logger is intentional,
|
||||
|
@ -93,64 +87,4 @@ def handle_event(
|
|||
end
|
||||
|
||||
def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok
|
||||
|
||||
def handle_event(
|
||||
[:pleroma, :repo, :query] = _name,
|
||||
%{query_time: query_time} = measurements,
|
||||
%{source: source} = metadata,
|
||||
config
|
||||
) do
|
||||
logging_config = Pleroma.Config.get([:telemetry, :slow_queries_logging], [])
|
||||
|
||||
if logging_config[:enabled] &&
|
||||
logging_config[:min_duration] &&
|
||||
query_time > logging_config[:min_duration] and
|
||||
(is_nil(logging_config[:exclude_sources]) or
|
||||
source not in logging_config[:exclude_sources]) do
|
||||
log_slow_query(measurements, metadata, config)
|
||||
else
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
defp log_slow_query(
|
||||
%{query_time: query_time} = _measurements,
|
||||
%{source: _source, query: query, params: query_params, repo: repo} = _metadata,
|
||||
_config
|
||||
) do
|
||||
sql_explain =
|
||||
with {:ok, %{rows: explain_result_rows}} <-
|
||||
repo.query("EXPLAIN " <> query, query_params, log: false) do
|
||||
Enum.map_join(explain_result_rows, "\n", & &1)
|
||||
end
|
||||
|
||||
{:current_stacktrace, stacktrace} = Process.info(self(), :current_stacktrace)
|
||||
|
||||
pleroma_stacktrace =
|
||||
Enum.filter(stacktrace, fn
|
||||
{__MODULE__, _, _, _} ->
|
||||
false
|
||||
|
||||
{mod, _, _, _} ->
|
||||
mod
|
||||
|> to_string()
|
||||
|> String.starts_with?("Elixir.Pleroma.")
|
||||
end)
|
||||
|
||||
Logger.warn(fn ->
|
||||
"""
|
||||
Slow query!
|
||||
|
||||
Total time: #{round(query_time / 1_000)} ms
|
||||
|
||||
#{query}
|
||||
|
||||
#{inspect(query_params, limit: :infinity)}
|
||||
|
||||
#{sql_explain}
|
||||
|
||||
#{Exception.format_stacktrace(pleroma_stacktrace)}
|
||||
"""
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2284,6 +2284,7 @@ def ensure_keys_present(%User{} = user) do
|
|||
def get_ap_ids_by_nicknames(nicknames) do
|
||||
from(u in User,
|
||||
where: u.nickname in ^nicknames,
|
||||
order_by: fragment("array_position(?, ?)", ^nicknames, u.nickname),
|
||||
select: u.ap_id
|
||||
)
|
||||
|> Repo.all()
|
||||
|
|
|
@ -2105,6 +2105,17 @@ test "it returns a list of AP ids for a given set of nicknames" do
|
|||
assert user.ap_id in ap_ids
|
||||
assert user_two.ap_id in ap_ids
|
||||
end
|
||||
|
||||
test "it returns a list of AP ids in the same order" do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
ap_ids =
|
||||
User.get_ap_ids_by_nicknames([user.nickname, user_three.nickname, user_two.nickname])
|
||||
|
||||
assert [user.ap_id, user_three.ap_id, user_two.ap_id] == ap_ids
|
||||
end
|
||||
end
|
||||
|
||||
describe "sync followers count" do
|
||||
|
|
Loading…
Reference in a new issue