mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
Disable sampling in the API
This commit is contained in:
parent
5df15e9169
commit
63b7abad58
@ -30,11 +30,19 @@ defmodule Plausible.Stats.Base do
|
||||
q =
|
||||
from(
|
||||
e in "events",
|
||||
hints: [sample: query.sample_threshold],
|
||||
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
|
||||
|
||||
q =
|
||||
case query.filters["event:page"] do
|
||||
{:is, page} ->
|
||||
|
@ -5,6 +5,8 @@ defmodule Plausible.Stats.Query do
|
||||
filters: %{},
|
||||
sample_threshold: 10_000_000
|
||||
|
||||
@default_sample_threshold 10_000_000
|
||||
|
||||
def shift_back(%__MODULE__{period: "month"} = query, site) do
|
||||
# Querying current month to date
|
||||
{new_first, new_last} =
|
||||
@ -42,7 +44,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "30m",
|
||||
interval: "minute",
|
||||
date_range: Date.range(date, date),
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -53,7 +56,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "day",
|
||||
date_range: Date.range(date, date),
|
||||
interval: "hour",
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -65,7 +69,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "7d",
|
||||
date_range: Date.range(start_date, end_date),
|
||||
interval: "date",
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -77,7 +82,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "30d",
|
||||
date_range: Date.range(start_date, end_date),
|
||||
interval: "date",
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -91,7 +97,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "month",
|
||||
date_range: Date.range(start_date, end_date),
|
||||
interval: "date",
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -108,7 +115,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "6mo",
|
||||
date_range: Date.range(start_date, end_date),
|
||||
interval: Map.get(params, "interval", "month"),
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -125,7 +133,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "12mo",
|
||||
date_range: Date.range(start_date, end_date),
|
||||
interval: Map.get(params, "interval", "month"),
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
@ -148,7 +157,8 @@ defmodule Plausible.Stats.Query do
|
||||
period: "custom",
|
||||
date_range: Date.range(from_date, to_date),
|
||||
interval: Map.get(params, "interval", "date"),
|
||||
filters: parse_filters(params)
|
||||
filters: parse_filters(params),
|
||||
sample_threshold: Map.get(params, "sample_threshold", @default_sample_threshold)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -12,6 +12,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController do
|
||||
|
||||
def aggregate(conn, params) do
|
||||
site = conn.assigns[:site]
|
||||
params = Map.put(params, "sample_threshold", "infinite")
|
||||
|
||||
with :ok <- validate_period(params),
|
||||
:ok <- validate_date(params),
|
||||
@ -52,6 +53,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController do
|
||||
|
||||
def breakdown(conn, params) do
|
||||
site = conn.assigns[:site]
|
||||
params = Map.put(params, "sample_threshold", "infinite")
|
||||
|
||||
with :ok <- validate_period(params),
|
||||
:ok <- validate_date(params),
|
||||
@ -124,6 +126,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController do
|
||||
|
||||
def timeseries(conn, params) do
|
||||
site = conn.assigns[:site]
|
||||
params = Map.put(params, "sample_threshold", "infinite")
|
||||
|
||||
with :ok <- validate_period(params),
|
||||
:ok <- validate_date(params),
|
||||
|
Loading…
Reference in New Issue
Block a user