Include sample_percent in both tables

pull/3966/head
Karl-Aksel Puulmann 3 years ago
parent 563da1a382
commit d2a999b728

@ -8,28 +8,30 @@ defmodule Plausible.Stats.TableDecider do
event: event_metrics,
session: session_metrics,
either: either_metrics,
other: other_metrics
other: other_metrics,
both: both_metrics
} =
partition(metrics, query, &metric_partitioner/2)
%{event: event_filters, session: session_filters, either: _either_filters} =
%{event: event_filters, session: session_filters} =
partition(query.filters, query, &filters_partitioner/2)
cond do
# Only one table needs to be queried
empty?(session_metrics) && empty?(session_filters) ->
{event_metrics ++ either_metrics, [], other_metrics}
{event_metrics ++ either_metrics ++ both_metrics, [], other_metrics}
empty?(event_metrics) && empty?(event_filters) ->
{[], session_metrics ++ either_metrics, other_metrics}
{[], session_metrics ++ either_metrics ++ both_metrics, other_metrics}
# Filters from either, but only one kind of metric
empty?(session_metrics) ->
{event_metrics ++ either_metrics, [], other_metrics}
{event_metrics ++ either_metrics ++ both_metrics, [], other_metrics}
# Default: prefer sessions
true ->
{event_metrics, session_metrics ++ either_metrics, other_metrics}
{event_metrics ++ both_metrics, session_metrics ++ either_metrics ++ both_metrics,
other_metrics}
end
end
@ -47,8 +49,8 @@ defmodule Plausible.Stats.TableDecider do
# :TODO: Calculated/weird metrics
defp metric_partitioner(_, :time_on_page), do: :other
defp metric_partitioner(_, :total_visitors), do: :other
# :TODO: Should be included on _both_
defp metric_partitioner(_, :sample_percent), do: :event
# Sample percentage is included in both tables if queried.
defp metric_partitioner(_, :sample_percent), do: :both
defp metric_partitioner(%Query{experimental_reduced_joins?: false}, unknown) do
raise ArgumentError, "Metric #{unknown} not supported without experimental_reduced_joins?"
@ -72,7 +74,7 @@ defmodule Plausible.Stats.TableDecider do
defp filters_partitioner(_, _), do: :either
@default %{event: [], session: [], either: [], other: []}
@default %{event: [], session: [], either: [], other: [], both: []}
defp partition(values, query, partitioner) do
Enum.reduce(values, @default, fn value, acc ->
key = partitioner.(query, value)

Loading…
Cancel
Save