Skip to content

Commit

Permalink
Use one case instead of nested ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
aerosol authored and ukutaht committed Feb 9, 2023
1 parent b2ed365 commit 39e346d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions lib/plausible/stats/props.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ defmodule Plausible.Stats.Props do
prop_filter =
Enum.find(query.filters, fn {key, _} -> String.starts_with?(key, "event:props:") end)

if prop_filter do
{"event:props:" <> key, {_, val}} = prop_filter

if val == "(none)" do
case prop_filter do
{"event:props:" <> key, {_, "(none)"}} ->
{_, _, goal_name} = query.filters["event:goal"]
%{goal_name => [key]}
else

{"event:props:" <> _key, _} ->
ClickhouseRepo.all(
from [e, meta: meta] in base_event_query(site, query),
select: {e.name, meta.key},
Expand All @@ -21,17 +20,17 @@ defmodule Plausible.Stats.Props do
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)
end
else
ClickhouseRepo.all(
from e in base_event_query(site, query),
inner_lateral_join: meta in fragment("meta as m"),
select: {e.name, meta.key},
distinct: true
)
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)

nil ->
ClickhouseRepo.all(
from e in base_event_query(site, query),
inner_lateral_join: meta in fragment("meta as m"),
select: {e.name, meta.key},
distinct: true
)
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)
end
end
end

0 comments on commit 39e346d

Please sign in to comment.