Skip to content

Commit

Permalink
Limit excluded goals to 1000 in goal suggestions (plausible#4319)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoldar authored Jul 8, 2024
1 parent 35596e8 commit 22b18db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/plausible/stats/goal_suggestions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ defmodule Plausible.Stats.GoalSuggestions do
import Plausible.Stats.Base
import Ecto.Query

# As excluded goal names are interpolated as separate
# parameters in the query, there's a risk of running
# against max parameters limit. Given the failure mode
# in this case is suggesting an event that is already
# added as a goal, which will be validated when creating,
# it's safe to trim exclusions list.
@max_excluded 1000

defmacrop visitors(e) do
quote do
selected_as(
Expand All @@ -23,7 +31,11 @@ defmodule Plausible.Stats.GoalSuggestions do
|> Repo.preload(:goals)
|> Plausible.Imported.load_import_data()

excluded = Keyword.get(opts, :exclude, [])
excluded =
opts
|> Keyword.get(:exclude, [])
|> Enum.take(@max_excluded)

limit = Keyword.get(opts, :limit, 25)

params = %{"with_imported" => "true", "period" => "6mo"}
Expand Down

0 comments on commit 22b18db

Please sign in to comment.