From d3ecbd4e17d9b093bb7ea7d3e4573c2138cecd0d Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 19 Aug 2021 13:18:22 +0300 Subject: [PATCH] Fix sampling --- lib/plausible/stats/base.ex | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex index c293aa6aa..129fd9932 100644 --- a/lib/plausible/stats/base.ex +++ b/lib/plausible/stats/base.ex @@ -33,15 +33,7 @@ defmodule Plausible.Stats.Base do where: e.domain == ^site.domain, where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime ) - - q = - case query.sample_threshold do - "infinite" -> - q - - threshold -> - from(e in q, hints: [sample: threshold]) - end + |> add_sample_hint(query) q = case query.filters["event:page"] do @@ -134,10 +126,10 @@ defmodule Plausible.Stats.Base do sessions_q = from( s in "sessions", - hints: [sample: query.sample_threshold], where: s.domain == ^site.domain, where: s.timestamp >= ^first_datetime and s.start < ^last_datetime ) + |> add_sample_hint(query) sessions_q = case {query.filters["visit:goal"], query.filters["visit:page"]} do @@ -352,4 +344,14 @@ defmodule Plausible.Stats.Base do |> String.replace(~r/\*\*/, ".*") |> String.replace(~r/(? + db_q + + threshold -> + from(e in db_q, hints: [sample: threshold]) + end + end end