Skip to content

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

Rename allowance to monthly_pageview_limit (#3273)

Vini Brasildad787cb4bc2
diff --git a/config/runtime.exs b/config/runtime.exs
index 6b02434b80..317d8b7b33 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -204,12 +204,6 @@ custom_script_name =
config_dir
|> get_var_from_path_or_env("CUSTOM_SCRIPT_NAME", "script")
-site_limit_exempt =
- config_dir
- |> get_var_from_path_or_env("SITE_LIMIT_EXEMPT", "")
- |> String.split(",")
- |> Enum.map(&String.trim/1)
-
disable_cron =
config_dir
|> get_var_from_path_or_env("DISABLE_CRON", "false")
@@ -241,7 +235,6 @@ config :plausible,
environment: env,
mailer_email: mailer_email,
super_admin_user_ids: super_admin_user_ids,
- site_limit_exempt: site_limit_exempt,
is_selfhost: is_selfhost,
custom_script_name: custom_script_name,
log_failed_login_attempts: log_failed_login_attempts
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex
index c9c2582abb..d5de085244 100644
--- a/lib/plausible/billing/billing.ex
+++ b/lib/plausible/billing/billing.ex
@@ -247,9 +247,10 @@ defmodule Plausible.Billing do
case user.grace_period do
%GracePeriod{allowance_required: allowance_required} ->
- new_allowance = Plausible.Billing.Plans.allowance(user.subscription)
+ new_monthly_pageview_limit =
+ Plausible.Billing.Plans.monthly_pageview_limit(user.subscription)
- if new_allowance > allowance_required do
+ if new_monthly_pageview_limit > allowance_required do
user
|> Plausible.Auth.GracePeriod.remove_changeset()
|> Repo.update!()
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index 19cc7c03ed..2feb849c29 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -116,7 +116,6 @@ defmodule Plausible.Billing.Plans do
def site_limit(user) do
cond do
Application.get_env(:plausible, :is_selfhost) -> :unlimited
- user.email in Application.get_env(:plausible, :site_limit_exempt) -> :unlimited
Timex.before?(user.inserted_at, @limit_sites_since) -> :unlimited
true -> get_site_limit_from_plan(user)
end
@@ -160,8 +159,8 @@ defmodule Plausible.Billing.Plans do
end
end
- @spec allowance(Plausible.Billing.Subscription.t()) :: non_neg_integer() | nil
- def allowance(subscription) do
+ @spec monthly_pageview_limit(Plausible.Billing.Subscription.t()) :: non_neg_integer() | nil
+ def monthly_pageview_limit(subscription) do
case get_subscription_plan(subscription) do
%Plausible.Billing.EnterprisePlan{monthly_pageview_limit: limit} ->
limit
@@ -173,7 +172,7 @@ defmodule Plausible.Billing.Plans do
10_000
_any ->
- Sentry.capture_message("Unknown allowance for plan",
+ Sentry.capture_message("Unknown monthly pageview limit for plan",
extra: %{paddle_plan_id: subscription.paddle_plan_id}
)
end
diff --git a/lib/plausible_web/views/auth_view.ex b/lib/plausible_web/views/auth_view.ex
index bc68d820e7..02a4d4751d 100644
--- a/lib/plausible_web/views/auth_view.ex
+++ b/lib/plausible_web/views/auth_view.ex
@@ -11,7 +11,9 @@ defmodule PlausibleWeb.AuthView do
end
def subscription_quota(subscription) do
- Plans.allowance(subscription) |> PlausibleWeb.StatsView.large_number_format()
+ subscription
+ |> Plans.monthly_pageview_limit()
+ |> PlausibleWeb.StatsView.large_number_format()
end
def subscription_interval(subscription) do
diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.ex
index 501ce623da..b69be996d3 100644
--- a/lib/workers/check_usage.ex
+++ b/lib/workers/check_usage.ex
@@ -112,13 +112,13 @@ defmodule Plausible.Workers.CheckUsage do
end
defp check_pageview_limit(subscriber, billing_mod) do
- allowance =
- case Plausible.Billing.Plans.allowance(subscriber.subscription) do
- allowance when is_number(allowance) ->
- allowance * 1.1
+ monthly_pageview_limit =
+ case Plausible.Billing.Plans.monthly_pageview_limit(subscriber.subscription) do
+ monthly_pageview_limit when is_number(monthly_pageview_limit) ->
+ monthly_pageview_limit * 1.1
- _allowance ->
- Sentry.capture_message("Unable to calculate allowance",
+ nil ->
+ Sentry.capture_message("Unable to calculate monthly pageview limit",
user: subscriber,
subscription: subscriber.subscription
)
@@ -129,7 +129,10 @@ defmodule Plausible.Workers.CheckUsage do
{last_last_cycle_usage, last_cycle_usage} =
billing_mod.last_two_billing_months_usage(subscriber)
- if last_last_cycle_usage >= allowance && last_cycle_usage >= allowance do
+ exceeded_last_cycle? = last_cycle_usage >= monthly_pageview_limit
+ exceeded_last_last_cycle? = last_last_cycle_usage >= monthly_pageview_limit
+
+ if exceeded_last_last_cycle? && exceeded_last_cycle? do
{:over_limit, {last_cycle, last_cycle_usage}}
else
{:within_limit, {last_cycle, last_cycle_usage}}
@@ -137,13 +140,13 @@ defmodule Plausible.Workers.CheckUsage do
end
defp check_site_limit(subscriber) do
- allowance = subscriber.enterprise_plan.site_limit
+ site_limit = subscriber.enterprise_plan.site_limit
total_sites = Plausible.Sites.owned_sites_count(subscriber)
- if total_sites >= allowance do
- {:over_limit, {total_sites, allowance}}
+ if total_sites >= site_limit do
+ {:over_limit, {total_sites, site_limit}}
else
- {:within_limit, {total_sites, allowance}}
+ {:within_limit, {total_sites, site_limit}}
end
end
end
diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs
index 3d2a49a0eb..c906c2997d 100644
--- a/test/plausible/billing/plans_test.exs
+++ b/test/plausible/billing/plans_test.exs
@@ -32,17 +32,17 @@ defmodule Plausible.Billing.PlansTest do
end
end
- describe "allowance" do
+ describe "monthly_pageview_limit" do
test "is based on the plan if user is on a standard plan" do
user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id))
- assert Plans.allowance(user.subscription) == 10_000
+ assert Plans.monthly_pageview_limit(user.subscription) == 10_000
end
- test "free_10k has 10k allowance" do
+ test "free_10k has 10k monthly_pageview_limit" do
user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k"))
- assert Plans.allowance(user.subscription) == 10_000
+ assert Plans.monthly_pageview_limit(user.subscription) == 10_000
end
test "is based on the enterprise plan if user is on an enterprise plan" do
@@ -54,7 +54,7 @@ defmodule Plausible.Billing.PlansTest do
subscription =
insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id)
- assert Plans.allowance(subscription) == 100_000
+ assert Plans.monthly_pageview_limit(subscription) == 100_000
end
end