summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-09-17 08:22:55 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-09-24 10:12:07 +0300
commit9bf2e3c47d1b39549e4d54c617204accdbbaf309 (patch)
treef16a29baea3d01afdf0c986b21d9790217a5d9b2
parent4f248de9a598e1c0089bd8f8a92bb743da8667ea (diff)
changes from review
-rw-r--r--lib/mix/pleroma.ex16
-rw-r--r--lib/pleroma/application/dependencies.ex10
-rw-r--r--lib/pleroma/application/dependencies_supervisor.ex30
-rw-r--r--lib/pleroma/config/config_db.ex4
4 files changed, 31 insertions, 29 deletions
diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex
index a3e9e7cf7..ec801403d 100644
--- a/lib/mix/pleroma.ex
+++ b/lib/mix/pleroma.ex
@@ -38,14 +38,14 @@ defmodule Mix.Pleroma do
Enum.each(apps, &Application.ensure_all_started/1)
- children =
- [
- Pleroma.Repo,
- Supervisor.child_spec({Task, &Pleroma.Config.Environment.load_and_update/0},
- id: :update_env
- ),
- Pleroma.Web.Endpoint
- ] ++ additional_childs
+ children = [
+ Pleroma.Repo,
+ Supervisor.child_spec({Task, &Pleroma.Config.Environment.load_and_update/0},
+ id: :update_env
+ ),
+ Pleroma.Web.Endpoint
+ | additional_childs
+ ]
children = [Pleroma.Application.Dependencies.adapter_module() | children]
diff --git a/lib/pleroma/application/dependencies.ex b/lib/pleroma/application/dependencies.ex
index c0170c7ed..6714d1f0a 100644
--- a/lib/pleroma/application/dependencies.ex
+++ b/lib/pleroma/application/dependencies.ex
@@ -155,10 +155,14 @@ defmodule Pleroma.Application.Dependencies do
end)
end
- @spec find_relations(module()) :: [relation()] | {:error, :relations_not_found}
+ @spec find_relations(module()) :: {:ok, [relation()]} | {:error, :relations_not_found}
def find_relations(module) do
- with [] <- Enum.filter(config_relations(), fn {_, m} -> m == module end) do
- {:error, :relations_not_found}
+ case Enum.filter(config_relations(), fn {_, m} -> m == module end) do
+ [] ->
+ {:error, :relations_not_found}
+
+ relations ->
+ {:ok, relations}
end
end
end
diff --git a/lib/pleroma/application/dependencies_supervisor.ex b/lib/pleroma/application/dependencies_supervisor.ex
index cca7a0ba9..013335ea5 100644
--- a/lib/pleroma/application/dependencies_supervisor.ex
+++ b/lib/pleroma/application/dependencies_supervisor.ex
@@ -34,11 +34,12 @@ defmodule Pleroma.Application.DependenciesSupervisor do
defp start_while(children, fun) do
Enum.reduce_while(children, :ok, fn child, acc ->
- with {:ok, _} <- fun.(child) do
- {:cont, acc}
- else
+ case fun.(child) do
+ {:ok, _} ->
+ {:cont, acc}
+
+ # consider this behavior is normal
:ignore ->
- # consider this behavior is normal
Logger.info("#{inspect(child)} is ignored.")
{:cont, acc}
@@ -54,19 +55,13 @@ defmodule Pleroma.Application.DependenciesSupervisor do
end
defp start_dynamic_child(child) do
- with {:ok, pid} = result <- dynamic_child(child),
- relations when is_list(relations) <- Dependencies.find_relations(child) do
+ with {:ok, relations} <- Dependencies.find_relations(child),
+ {:ok, pid} <- DynamicSupervisor.start_child(__MODULE__, spec(child)) do
Enum.each(relations, fn {key, _} ->
DependenciesState.put_pid(key, pid)
end)
- result
- end
- end
-
- defp dynamic_child(child) do
- with {:error, _} = error <- DynamicSupervisor.start_child(__MODULE__, spec(child)) do
- error
+ {:ok, pid}
end
end
@@ -95,9 +90,10 @@ defmodule Pleroma.Application.DependenciesSupervisor do
def restart_children do
DependenciesState.get_and_reset_paths()
|> Enum.reduce_while(:ok, fn path, acc ->
- with {:ok, _} <- restart_child(path) do
- {:cont, acc}
- else
+ case restart_child(path) do
+ {:ok, _} ->
+ {:cont, acc}
+
:ignore ->
Logger.info("path #{inspect(path)} is ignored.")
{:cont, acc}
@@ -127,7 +123,7 @@ defmodule Pleroma.Application.DependenciesSupervisor do
with {_, module} <- Dependencies.find_relation(path),
:ok <- terminate(pid, module),
# then we search for mappings, which depends on this main module
- relations when is_list(relations) <- Dependencies.find_relations(module) do
+ {:ok, relations} <- Dependencies.find_relations(module) do
Enum.each(relations, fn {key, _} ->
DependenciesState.delete_pid(key)
end)
diff --git a/lib/pleroma/config/config_db.ex b/lib/pleroma/config/config_db.ex
index 862c06f0a..df21e34e0 100644
--- a/lib/pleroma/config/config_db.ex
+++ b/lib/pleroma/config/config_db.ex
@@ -382,7 +382,9 @@ defmodule Pleroma.ConfigDB do
@spec load_and_merge_with_defaults([t()]) :: [{atom(), atom(), term(), term()}]
def load_and_merge_with_defaults(deleted \\ []) do
- (Repo.all(ConfigDB) ++ deleted)
+ ConfigDB
+ |> Repo.all()
+ |> Enum.concat(deleted)
|> Enum.map(&merge_with_defaults/1)
end