Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Stop segment queries when not needed (#5043)

Artur Pata15d78bd9a84a
diff --git a/lib/plausible/segments/segments.ex b/lib/plausible/segments/segments.ex
index 37f420e6d6..3ede54ff66 100644
--- a/lib/plausible/segments/segments.ex
+++ b/lib/plausible/segments/segments.ex
@@ -39,7 +39,13 @@ defmodule Plausible.Segments do
@spec get_many(Plausible.Site.t(), list(pos_integer()), Keyword.t()) ::
{:ok, [Segment.t()]}
- def get_many(%Plausible.Site{} = site, segment_ids, opts) when is_list(segment_ids) do
+ def get_many(%Plausible.Site{} = _site, segment_ids, _opts)
+ when segment_ids == [] do
+ {:ok, []}
+ end
+
+ def get_many(%Plausible.Site{} = site, segment_ids, opts)
+ when is_list(segment_ids) do
fields = Keyword.get(opts, :fields, [:id])
query =