Skip to content

Commit d56a4fd

Browse files
committed
WIP
1 parent ac69e7e commit d56a4fd

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

lib/plausible/clickhouse_repo.ex

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,45 @@ defmodule Plausible.ClickhouseRepo do
5959
log_comment = Jason.encode!(log_comment_data)
6060

6161
opts =
62-
Keyword.update(opts, :settings, [log_comment: log_comment], fn settings ->
63-
[{:log_comment, log_comment} | settings]
62+
opts
63+
|> Keyword.update(:settings, [log_comment: log_comment], fn current_settings ->
64+
[{:log_comment, log_comment} | current_settings]
6465
end)
6566

67+
opts =
68+
if plausible_query do
69+
opts
70+
|> Keyword.update!(:settings, fn current_settings ->
71+
Enum.concat(get_extra_connection_settings(log_comment_data), current_settings)
72+
end)
73+
else
74+
opts
75+
end
76+
6677
{query, opts}
6778
end
6879

80+
defp get_extra_connection_settings(%{params: params}) do
81+
keys =
82+
params
83+
|> Map.keys()
84+
|> Enum.filter(fn k ->
85+
case k do
86+
"clickhouse_readonly" -> false
87+
"clickhouse_" <> _k -> true
88+
_ -> false
89+
end
90+
end)
91+
92+
Enum.map(keys, fn k ->
93+
{String.to_atom(String.trim_leading(k, "clickhouse_")), params[k]}
94+
end)
95+
end
96+
97+
defp get_extra_connection_settings(_) do
98+
[]
99+
end
100+
69101
def get_config_without_ch_query_execution_timeout() do
70102
{settings, config} = Plausible.ClickhouseRepo.config() |> Keyword.pop!(:settings)
71103

0 commit comments

Comments
 (0)