X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fconfig%2Ftransfer_task.ex;h=2e4bcb0ee02b7a3c14643d7f4e63c5710ff57fd6;hb=c2054f82abbd67045de21e232e0731e6dbac55a0;hp=c02b70e96691b18647ba7ceef83419dfd19b125f;hpb=6b84c62d4a51cb17192945d1b67999b2c56a23d2;p=akkoma
diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex
index c02b70e96..2e4bcb0ee 100644
--- a/lib/pleroma/config/transfer_task.ex
+++ b/lib/pleroma/config/transfer_task.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.TransferTask do
@@ -13,30 +13,23 @@ defmodule Pleroma.Config.TransferTask do
@type env() :: :test | :benchmark | :dev | :prod
- @reboot_time_keys [
- {:pleroma, :hackney_pools},
- {:pleroma, :chat},
- {:pleroma, Oban},
- {:pleroma, :rate_limit},
- {:pleroma, :markup},
- {:pleroma, :streamer},
- {:pleroma, :pools},
- {:pleroma, :connections_pool}
- ]
-
- @reboot_time_subkeys [
- {:pleroma, Pleroma.Captcha, [:seconds_valid]},
- {:pleroma, Pleroma.Upload, [:proxy_remote]},
- {:pleroma, :instance, [:upload_limit]},
- {:pleroma, :email_notifications, [:digest]},
- {:pleroma, :oauth2, [:clean_expired_tokens]},
- {:pleroma, Pleroma.ActivityExpiration, [:enabled]},
- {:pleroma, Pleroma.ScheduledActivity, [:enabled]},
- {:pleroma, :gopher, [:enabled]}
- ]
-
- def start_link(_) do
- load_and_update_env()
+ defp reboot_time_keys,
+ do: [
+ {:pleroma, Oban},
+ {:pleroma, :rate_limit},
+ {:pleroma, :markup},
+ {:pleroma, :streamer}
+ ]
+
+ defp reboot_time_subkeys,
+ do: [
+ {:pleroma, Pleroma.Captcha, [:seconds_valid]},
+ {:pleroma, Pleroma.Upload, [:proxy_remote]},
+ {:pleroma, :instance, [:upload_limit]}
+ ]
+
+ def start_link(restart_pleroma? \\ true) do
+ load_and_update_env([], restart_pleroma?)
if Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Repo)
:ignore
end
@@ -45,11 +38,10 @@ defmodule Pleroma.Config.TransferTask do
def load_and_update_env(deleted_settings \\ [], restart_pleroma? \\ true) do
with {_, true} <- {:configurable, Config.get(:configurable_from_database)} do
# We need to restart applications for loaded settings take effect
-
{logger, other} =
(Repo.all(ConfigDB) ++ deleted_settings)
- |> Enum.map(&transform_and_merge/1)
- |> Enum.split_with(fn {group, _, _, _} -> group in [:logger, :quack] end)
+ |> Enum.map(&merge_with_default/1)
+ |> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
logger
|> Enum.sort()
@@ -57,8 +49,7 @@ defmodule Pleroma.Config.TransferTask do
started_applications = Application.started_applications()
- # TODO: some problem with prometheus after restart!
- reject = [nil, :prometheus, :postgrex]
+ reject = [nil, :postgrex]
reject =
if restart_pleroma? do
@@ -92,12 +83,13 @@ defmodule Pleroma.Config.TransferTask do
end
end
- defp transform_and_merge(%{group: group, key: key, value: value} = setting) do
- group = ConfigDB.from_string(group)
- key = ConfigDB.from_string(key)
- value = ConfigDB.from_binary(value)
-
- default = Config.Holder.default_config(group, key)
+ defp merge_with_default(%{group: group, key: key, value: value} = setting) do
+ default =
+ if group == :pleroma do
+ Config.get([key], Config.Holder.default_config(group, key))
+ else
+ Config.Holder.default_config(group, key)
+ end
merged =
cond do
@@ -109,12 +101,6 @@ defmodule Pleroma.Config.TransferTask do
{group, key, value, merged}
end
- # change logger configuration in runtime, without restart
- defp configure({:quack, key, _, merged}) do
- Logger.configure_backend(Quack.Logger, [{key, merged}])
- :ok = update_env(:quack, key, merged)
- end
-
defp configure({_, :backends, _, merged}) do
# removing current backends
Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1)
@@ -154,9 +140,7 @@ defmodule Pleroma.Config.TransferTask do
rescue
error ->
error_msg =
- "updating env causes error, group: #{inspect(group)}, key: #{inspect(key)}, value: #{
- inspect(value)
- } error: #{inspect(error)}"
+ "updating env causes error, group: #{inspect(group)}, key: #{inspect(key)}, value: #{inspect(value)} error: #{inspect(error)}"
Logger.warn(error_msg)
@@ -173,12 +157,12 @@ defmodule Pleroma.Config.TransferTask do
end
defp group_and_key_need_reboot?(group, key) do
- Enum.any?(@reboot_time_keys, fn {g, k} -> g == group and k == key end)
+ Enum.any?(reboot_time_keys(), fn {g, k} -> g == group and k == key end)
end
defp group_and_subkey_need_reboot?(group, key, value) do
Keyword.keyword?(value) and
- Enum.any?(@reboot_time_subkeys, fn {g, k, subkeys} ->
+ Enum.any?(reboot_time_subkeys(), fn {g, k, subkeys} ->
g == group and k == key and
Enum.any?(Keyword.keys(value), &(&1 in subkeys))
end)