diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index f7d17a858..688d05d4e 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -649,7 +649,7 @@ defmodule Plausible.Stats.Clickhouse do q = from(s in "sessions", where: s.domain == ^site.domain, - where: s.start >= ^first_datetime and s.start < ^last_datetime + where: s.timestamp >= ^first_datetime and s.start < ^last_datetime ) q = @@ -708,17 +708,15 @@ defmodule Plausible.Stats.Clickhouse do end end - defp utc_boundaries(%Query{period: "30m"}, timezone) do - last_datetime = - NaiveDateTime.utc_now() |> Timex.to_datetime(timezone) |> Timex.Timezone.convert("UTC") + defp utc_boundaries(%Query{period: "30m"}, _timezone) do + last_datetime = NaiveDateTime.utc_now() first_datetime = last_datetime |> Timex.shift(minutes: -30) {first_datetime, last_datetime} end - defp utc_boundaries(%Query{period: "realtime"}, timezone) do - last_datetime = - NaiveDateTime.utc_now() |> Timex.to_datetime(timezone) |> Timex.Timezone.convert("UTC") + defp utc_boundaries(%Query{period: "realtime"}, _timezone) do + last_datetime = NaiveDateTime.utc_now() first_datetime = last_datetime |> Timex.shift(minutes: -5) {first_datetime, last_datetime} diff --git a/test/support/clickhouse_setup.ex b/test/support/clickhouse_setup.ex index ff6d0e593..aecac94f3 100644 --- a/test/support/clickhouse_setup.ex +++ b/test/support/clickhouse_setup.ex @@ -218,7 +218,8 @@ defmodule Plausible.Test.ClickhouseSetup do session_id: @conversion_1_session_id, is_bounce: true, duration: 100, - start: ~N[2019-01-01 02:00:00] + start: ~N[2019-01-01 02:00:00], + timestamp: ~N[2019-01-01 02:00:00] }, %{ domain: "test-site.com", @@ -229,7 +230,8 @@ defmodule Plausible.Test.ClickhouseSetup do session_id: @conversion_2_session_id, is_bounce: false, duration: 0, - start: ~N[2019-01-01 02:00:00] + start: ~N[2019-01-01 02:00:00], + timestamp: ~N[2019-01-01 02:00:00] }, %{ domain: "test-site.com", @@ -239,7 +241,8 @@ defmodule Plausible.Test.ClickhouseSetup do referrer: "", is_bounce: false, duration: 100, - start: ~N[2019-01-01 03:00:00] + start: ~N[2019-01-01 03:00:00], + timestamp: ~N[2019-01-01 03:00:00] }, %{ domain: "test-site.com",