Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Make Finch pools lighter for self-hosting (#2250)

Uku Taht3d54b88f0a9a
diff --git a/config/runtime.exs b/config/runtime.exs
index 5b01a1c26a..0730f78616 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -372,12 +372,6 @@ config :plausible, :hcaptcha,
sitekey: hcaptcha_sitekey,
secret: hcaptcha_secret
-config :plausible, Plausible.Finch,
- default_pool_size: get_int_from_path_or_env(config_dir, "DEFAULT_FINCH_POOL_SIZE", 50),
- default_pool_count: get_int_from_path_or_env(config_dir, "DEFAULT_FINCH_POOL_COUNT", 1),
- sentry_pool_size: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_SIZE", 50),
- sentry_pool_count: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_COUNT", 1)
-
config :plausible, Plausible.Sentry.Client,
finch_request_opts: [
pool_timeout: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_TIMEOUT", 5000),
diff --git a/lib/plausible/application.ex b/lib/plausible/application.ex
index 579740b420..c0a8b9da93 100644
--- a/lib/plausible/application.ex
+++ b/lib/plausible/application.ex
@@ -41,41 +41,53 @@ defmodule Plausible.Application do
end
defp finch_pool_config() do
- config = Application.fetch_env!(:plausible, Plausible.Finch)
-
- pool_config = %{
- :default => [size: config[:default_pool_size], count: config[:default_pool_count]],
- "https://vendors.paddle.com" => [
- protocol: :http2,
- count: 50,
- conn_opts: [transport_opts: [timeout: 15_000]]
- ],
- "https://www.googleapis.com" => [
- protocol: :http2,
- count: 200,
- conn_opts: [transport_opts: [timeout: 15_000]]
- ],
- "https://analyticsreporting.googleapis.com" => [
- protocol: :http2,
- count: 200,
- conn_opts: [transport_opts: [timeout: 15_000]]
- ],
+ base_config = %{
"https://icons.duckduckgo.com" => [
- protocol: :http2,
- count: 100,
conn_opts: [transport_opts: [timeout: 15_000]]
]
}
- sentry_dsn = Application.get_env(:sentry, :dsn)
+ base_config
+ |> maybe_add_sentry_pool()
+ |> maybe_add_paddle_pool()
+ |> maybe_add_google_pools()
+ end
+
+ defp maybe_add_sentry_pool(pool_config) do
+ case Application.get_env(:sentry, :dsn) do
+ dsn when is_binary(dsn) ->
+ Map.put(pool_config, dsn, size: 50)
+
+ _ ->
+ pool_config
+ end
+ end
+
+ defp maybe_add_paddle_pool(pool_config) do
+ paddle_conf = Application.get_env(:plausible, :paddle)
+
+ cond do
+ paddle_conf[:vendor_id] && paddle_conf[:vendor_auth_code] ->
+ Map.put(pool_config, Plausible.Billing.PaddleApi.vendors_domain(),
+ conn_opts: [transport_opts: [timeout: 15_000]]
+ )
+
+ true ->
+ pool_config
+ end
+ end
+
+ defp maybe_add_google_pools(pool_config) do
+ google_conf = Application.get_env(:plausible, :google)
+
+ cond do
+ google_conf[:client_id] && google_conf[:client_secret] ->
+ pool_config
+ |> Map.put(google_conf[:api_url], conn_opts: [transport_opts: [timeout: 15_000]])
+ |> Map.put(google_conf[:reporting_api_url], conn_opts: [transport_opts: [timeout: 15_000]])
- if is_binary(sentry_dsn) do
- Map.put(pool_config, sentry_dsn,
- size: config[:sentry_pool_size],
- count: config[:sentry_pool_count]
- )
- else
- pool_config
+ true ->
+ pool_config
end
end