Skip to content

Commit 4e1b30a

Browse files
committed
Remove unnecessary logic
1 parent 7ec1ade commit 4e1b30a

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

lib/plausible/clickhouse_repo.ex

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,54 +61,39 @@ defmodule Plausible.ClickhouseRepo do
6161
opts =
6262
opts
6363
|> Keyword.update(:settings, [log_comment: log_comment], fn current_settings ->
64-
[{:log_comment, log_comment} | current_settings]
65-
end)
66-
67-
opts =
68-
if plausible_query do
69-
opts
70-
|> Keyword.update!(:settings, fn current_settings ->
71-
current_settings |> Enum.concat(get_extra_connection_settings(log_comment_data))
72-
end)
73-
|> Keyword.update!(:settings, fn current_settings ->
74-
should_use_workload? =
75-
Map.get(plausible_query.debug_metadata, :phoenix_controller, nil) in [
76-
PlausibleWeb.Api.ExternalStatsController |> to_string(),
77-
PlausibleWeb.Api.ExternalQueryApiController |> to_string()
78-
]
79-
80-
if should_use_workload? do
81-
[{:workload, "external_api"} | current_settings]
64+
extra_settings =
65+
on_ee do
66+
get_extra_connection_settings(plausible_query)
8267
else
83-
current_settings
68+
[]
8469
end
85-
end)
86-
else
87-
opts
88-
end
8970

90-
{query, opts}
91-
end
92-
93-
defp get_extra_connection_settings(%{params: params}) do
94-
keys =
95-
params
96-
|> Map.keys()
97-
|> Enum.filter(fn k ->
98-
case k do
99-
"clickhouse_readonly" -> false
100-
"clickhouse_" <> _k -> true
101-
_ -> false
102-
end
71+
[{:log_comment, log_comment}]
72+
|> Enum.concat(extra_settings)
73+
|> Enum.concat(current_settings)
10374
end)
10475

105-
Enum.map(keys, fn k ->
106-
{k |> String.trim_leading("clickhouse_") |> String.to_atom(), params[k]}
107-
end)
76+
{query, opts}
10877
end
10978

110-
defp get_extra_connection_settings(_) do
111-
[]
79+
on_ee do
80+
@external_controllers [
81+
PlausibleWeb.Api.ExternalStatsController |> to_string(),
82+
PlausibleWeb.Api.ExternalQueryApiController |> to_string()
83+
]
84+
defp get_extra_connection_settings(
85+
%{debug_metadata: %{phoenix_controller: controller}} = _plausible_query
86+
) do
87+
if controller in @external_controllers do
88+
[{:workload, "external_api"}]
89+
else
90+
[]
91+
end
92+
end
93+
94+
defp get_extra_connection_settings(_plausible_query) do
95+
[]
96+
end
11297
end
11398

11499
def get_config_without_ch_query_execution_timeout() do

lib/plausible_web/controllers/api/system_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule PlausibleWeb.Api.SystemController do
4141

4242
clickhouse_health_task =
4343
Task.async(fn ->
44-
Plausible.ClickhouseRepo.query("SELECT 1", [], [settings: [workload: "ingestion"]])
44+
Ecto.Adapters.SQL.query(Plausible.ClickhouseRepo, "SELECT 1", [])
4545
end)
4646

4747
postgres_health =

0 commit comments

Comments
 (0)