Use one typespec for two clauses

This commit is contained in:
Adam Rutkowski 2023-11-29 10:21:17 +01:00
parent 00b68779ed
commit 8d8cd21764

View File

@ -6,7 +6,8 @@ defmodule Plausible.Stats.Sampling do
import Ecto.Query
@spec add_query_hint(Ecto.Query.t(), Plausible.Stats.Query.t()) :: Ecto.Query.t()
@spec add_query_hint(Ecto.Query.t(), Plausible.Stats.Query.t() | pos_integer()) ::
Ecto.Query.t()
def add_query_hint(%Ecto.Query{} = db_query, %Plausible.Stats.Query{} = query) do
case query.sample_threshold do
:infinite ->
@ -17,7 +18,6 @@ defmodule Plausible.Stats.Sampling do
end
end
@spec add_query_hint(Ecto.Query.t(), pos_integer()) :: Ecto.Query.t()
def add_query_hint(%Ecto.Query{} = query, threshold) when is_integer(threshold) do
from(x in query, hints: [sample: threshold])
end