Add memory-backed benchmark profile

This commit is contained in:
2026-03-18 18:26:54 +01:00
parent 2225dfdc9e
commit f60b8ba02a
10 changed files with 278 additions and 56 deletions

View File

@@ -19,27 +19,55 @@ defmodule Parrhesia.PostgresRepos do
@spec started_repos() :: [module()]
def started_repos do
if separate_read_pool_enabled?() do
[Repo, ReadRepo]
else
[Repo]
cond do
not postgres_enabled?() ->
[]
separate_read_pool_enabled?() ->
[Repo, ReadRepo]
true ->
[Repo]
end
end
@spec postgres_enabled?() :: boolean()
def postgres_enabled? do
case Process.whereis(Config) do
pid when is_pid(pid) ->
Config.get([:storage, :backend], storage_backend_default()) == :postgres
nil ->
storage_backend_default() == :postgres
end
end
@spec separate_read_pool_enabled?() :: boolean()
def separate_read_pool_enabled? do
case Process.whereis(Config) do
pid when is_pid(pid) ->
Config.get([:database, :separate_read_pool?], application_default())
case {postgres_enabled?(), Process.whereis(Config)} do
{false, _pid} ->
false
nil ->
application_default()
{true, pid} when is_pid(pid) ->
Config.get(
[:database, :separate_read_pool?],
application_default(:separate_read_pool?, false)
)
{true, nil} ->
application_default(:separate_read_pool?, false)
end
end
defp application_default do
defp application_default(key, default) do
:parrhesia
|> Application.get_env(:database, [])
|> Keyword.get(:separate_read_pool?, false)
|> Keyword.get(key, default)
end
defp storage_backend_default do
:parrhesia
|> Application.get_env(:storage, [])
|> Keyword.get(:backend, :postgres)
end
end

View File

@@ -13,12 +13,20 @@ defmodule Parrhesia.Storage.Supervisor do
@impl true
def init(_init_arg) do
children =
[
{Parrhesia.Storage.Adapters.Postgres.ModerationCache,
name: Parrhesia.Storage.Adapters.Postgres.ModerationCache}
] ++ PostgresRepos.started_repos()
children = moderation_cache_children() ++ PostgresRepos.started_repos()
Supervisor.init(children, strategy: :one_for_one)
end
defp moderation_cache_children do
if PostgresRepos.postgres_enabled?() and
Application.get_env(:parrhesia, :moderation_cache_enabled, true) do
[
{Parrhesia.Storage.Adapters.Postgres.ModerationCache,
name: Parrhesia.Storage.Adapters.Postgres.ModerationCache}
]
else
[]
end
end
end

View File

@@ -25,9 +25,13 @@ defmodule Parrhesia.Tasks.Supervisor do
end
defp partition_retention_children do
[
{Parrhesia.Tasks.PartitionRetentionWorker, name: Parrhesia.Tasks.PartitionRetentionWorker}
]
if Application.get_env(:parrhesia, :enable_partition_retention_worker, true) do
[
{Parrhesia.Tasks.PartitionRetentionWorker, name: Parrhesia.Tasks.PartitionRetentionWorker}
]
else
[]
end
end
defp nip66_children do