Skip to content

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

Fix check_usage

Uku Taht7fe50c3ef29c
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index 743ac9be4f..e3650e111a 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -74,8 +74,11 @@ defmodule Plausible.Billing.Plans do
end
def allowance(subscription) do
- Enum.find(@all_plans, fn plan -> plan[:product_id] == subscription.paddle_plan_id end)
- |> Map.fetch!(:limit)
+ found = Enum.find(@all_plans, fn plan -> plan[:product_id] == subscription.paddle_plan_id end)
+
+ if found do
+ Map.fetch!(found, :limit)
+ end
end
defp number_format(num) do
diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.ex
index 5b7b0ca165..37206b46a0 100644
--- a/lib/workers/check_usage.ex
+++ b/lib/workers/check_usage.ex
@@ -39,6 +39,7 @@ defmodule Plausible.Workers.CheckUsage do
join: s in Plausible.Billing.Subscription,
on: s.user_id == u.id,
where: s.status == "active",
+ where: not is_nil(s.last_bill_date),
# Accounts for situations like last_bill_date==2021-01-31 AND today==2021-03-01. Since February never reaches the 31st day, the account is checked on 2021-03-01.
where:
least(day_of_month(s.last_bill_date), day_of_month(last_day_of_month(^yesterday))) ==