Escape quote in event name

This commit is contained in:
Uku Taht 2020-05-21 19:14:45 +03:00
parent ee4f604712
commit 439a4a80c7
2 changed files with 3 additions and 4 deletions

View File

@ -98,13 +98,12 @@ defmodule Mix.Tasks.HydrateClickhouse do
end
def hydrate_events(repo, _args \\ []) do
start_time = ~N[2020-05-01 00:00:00]
end_time = ~N[2020-05-21 10:46:51]
total = Repo.aggregate(from(e in Plausible.Event, where: e.timestamp < ^end_time and e.timestamp >= ^start_time), :count, :id)
total = Repo.aggregate(from(e in Plausible.Event, where: e.timestamp < ^end_time), :count, :id)
event_chunks = from(
e in Plausible.Event,
where: e.timestamp < ^end_time and e.timestamp >= ^start_time,
where: e.timestamp < ^end_time,
order_by: e.id
) |> chunk_query(50_000, repo)

View File

@ -16,7 +16,7 @@ defmodule Plausible.Clickhouse do
""" <> String.duplicate(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),", length(events))
args = Enum.reduce(events, [], fn event, acc ->
[event.name, event.timestamp, event.domain, event.user_id, event.session_id, event.hostname, escape_quote(event.pathname), escape_quote(event.referrer || ""), escape_quote(event.referrer_source || ""), escape_quote(event.initial_referrer || ""), escape_quote(event.initial_referrer_source || ""), event.country_code || "", event.screen_size || "", event.browser || "", event.operating_system || ""] ++ acc
[escape_quote(event.name), event.timestamp, event.domain, event.user_id, event.session_id, event.hostname, escape_quote(event.pathname), escape_quote(event.referrer || ""), escape_quote(event.referrer_source || ""), escape_quote(event.initial_referrer || ""), escape_quote(event.initial_referrer_source || ""), event.country_code || "", event.screen_size || "", event.browser || "", event.operating_system || ""] ++ acc
end)
Clickhousex.query(:clickhouse, insert, args, log: {Plausible.Clickhouse, :log, []})