using Pleroma.Config instead of ets

This commit is contained in:
Alexander Strizhakov 2020-03-11 17:22:50 +03:00
parent 193d67cde5
commit fce090c1de
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
2 changed files with 8 additions and 13 deletions

View file

@ -31,7 +31,7 @@ defmodule Pleroma.Application do
# See http://elixir-lang.org/docs/stable/elixir/Application.html # See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications # for more information on OTP Applications
def start(_type, _args) do def start(_type, _args) do
Pleroma.Config.Holder.to_ets() Pleroma.Config.Holder.save_default()
Pleroma.HTML.compile_scrubbers() Pleroma.HTML.compile_scrubbers()
Pleroma.Config.DeprecationWarnings.warn() Pleroma.Config.DeprecationWarnings.warn()
Pleroma.Plugs.HTTPSecurityPlug.warn_if_disabled() Pleroma.Plugs.HTTPSecurityPlug.warn_if_disabled()

View file

@ -5,10 +5,8 @@
defmodule Pleroma.Config.Holder do defmodule Pleroma.Config.Holder do
@config Pleroma.Config.Loader.default_config() @config Pleroma.Config.Loader.default_config()
@spec to_ets() :: true @spec save_default() :: :ok
def to_ets do def save_default do
:ets.new(:default_config, [:named_table, :protected])
default_config = default_config =
if System.get_env("RELEASE_NAME") do if System.get_env("RELEASE_NAME") do
release_config = release_config =
@ -21,20 +19,17 @@ defmodule Pleroma.Config.Holder do
@config @config
end end
:ets.insert(:default_config, {:config, default_config}) Pleroma.Config.put(:default_config, default_config)
end end
@spec default_config() :: keyword() @spec default_config() :: keyword()
def default_config, do: from_ets() def default_config, do: get_default()
@spec default_config(atom()) :: keyword() @spec default_config(atom()) :: keyword()
def default_config(group), do: Keyword.get(from_ets(), group) def default_config(group), do: Keyword.get(get_default(), group)
@spec default_config(atom(), atom()) :: keyword() @spec default_config(atom(), atom()) :: keyword()
def default_config(group, key), do: get_in(from_ets(), [group, key]) def default_config(group, key), do: get_in(get_default(), [group, key])
defp from_ets do defp get_default, do: Pleroma.Config.get(:default_config)
[{:config, default_config}] = :ets.lookup(:default_config, :config)
default_config
end
end end