forked from AkkomaGang/akkoma
Config: use runtime deps instead of module attributes
Speeds up recompilation time by breaking compile-time cycles
This commit is contained in:
parent
b221d77a6d
commit
32d263cb90
2 changed files with 35 additions and 31 deletions
|
@ -3,19 +3,21 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Config.Loader do
|
defmodule Pleroma.Config.Loader do
|
||||||
@reject_keys [
|
defp reject_keys,
|
||||||
Pleroma.Repo,
|
do: [
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Repo,
|
||||||
:env,
|
Pleroma.Web.Endpoint,
|
||||||
:configurable_from_database,
|
:env,
|
||||||
:database,
|
:configurable_from_database,
|
||||||
:swarm
|
:database,
|
||||||
]
|
:swarm
|
||||||
|
]
|
||||||
|
|
||||||
@reject_groups [
|
defp reject_groups,
|
||||||
:postgrex,
|
do: [
|
||||||
:tesla
|
:postgrex,
|
||||||
]
|
:tesla
|
||||||
|
]
|
||||||
|
|
||||||
if Code.ensure_loaded?(Config.Reader) do
|
if Code.ensure_loaded?(Config.Reader) do
|
||||||
@reader Config.Reader
|
@reader Config.Reader
|
||||||
|
@ -52,7 +54,7 @@ defp filter(configs) do
|
||||||
@spec filter_group(atom(), keyword()) :: keyword()
|
@spec filter_group(atom(), keyword()) :: keyword()
|
||||||
def filter_group(group, configs) do
|
def filter_group(group, configs) do
|
||||||
Enum.reject(configs[group], fn {key, _v} ->
|
Enum.reject(configs[group], fn {key, _v} ->
|
||||||
key in @reject_keys or group in @reject_groups or
|
key in reject_keys() or group in reject_groups() or
|
||||||
(group == :phoenix and key == :serve_endpoints)
|
(group == :phoenix and key == :serve_endpoints)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,23 +13,25 @@ defmodule Pleroma.Config.TransferTask do
|
||||||
|
|
||||||
@type env() :: :test | :benchmark | :dev | :prod
|
@type env() :: :test | :benchmark | :dev | :prod
|
||||||
|
|
||||||
@reboot_time_keys [
|
defp reboot_time_keys,
|
||||||
{:pleroma, :hackney_pools},
|
do: [
|
||||||
{:pleroma, :chat},
|
{:pleroma, :hackney_pools},
|
||||||
{:pleroma, Oban},
|
{:pleroma, :chat},
|
||||||
{:pleroma, :rate_limit},
|
{:pleroma, Oban},
|
||||||
{:pleroma, :markup},
|
{:pleroma, :rate_limit},
|
||||||
{:pleroma, :streamer},
|
{:pleroma, :markup},
|
||||||
{:pleroma, :pools},
|
{:pleroma, :streamer},
|
||||||
{:pleroma, :connections_pool}
|
{:pleroma, :pools},
|
||||||
]
|
{:pleroma, :connections_pool}
|
||||||
|
]
|
||||||
|
|
||||||
@reboot_time_subkeys [
|
defp reboot_time_subkeys,
|
||||||
{:pleroma, Pleroma.Captcha, [:seconds_valid]},
|
do: [
|
||||||
{:pleroma, Pleroma.Upload, [:proxy_remote]},
|
{:pleroma, Pleroma.Captcha, [:seconds_valid]},
|
||||||
{:pleroma, :instance, [:upload_limit]},
|
{:pleroma, Pleroma.Upload, [:proxy_remote]},
|
||||||
{:pleroma, :gopher, [:enabled]}
|
{:pleroma, :instance, [:upload_limit]},
|
||||||
]
|
{:pleroma, :gopher, [:enabled]}
|
||||||
|
]
|
||||||
|
|
||||||
def start_link(restart_pleroma? \\ true) do
|
def start_link(restart_pleroma? \\ true) do
|
||||||
load_and_update_env([], restart_pleroma?)
|
load_and_update_env([], restart_pleroma?)
|
||||||
|
@ -165,12 +167,12 @@ def pleroma_need_restart?(group, key, value) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp group_and_key_need_reboot?(group, key) do
|
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
|
end
|
||||||
|
|
||||||
defp group_and_subkey_need_reboot?(group, key, value) do
|
defp group_and_subkey_need_reboot?(group, key, value) do
|
||||||
Keyword.keyword?(value) and
|
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
|
g == group and k == key and
|
||||||
Enum.any?(Keyword.keys(value), &(&1 in subkeys))
|
Enum.any?(Keyword.keys(value), &(&1 in subkeys))
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue