OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: avoid exceed limit on self-hosting
Carl-Gerhard Lindesvärdda95f4cf12ed
diff --git a/apps/start/src/routes/_app.$organizationId.tsx b/apps/start/src/routes/_app.$organizationId.tsxindex b5b57ce61..0bcb911a6 100644--- a/apps/start/src/routes/_app.$organizationId.tsx+++ b/apps/start/src/routes/_app.$organizationId.tsx@@ -155,7 +155,8 @@ function Component() {</Alert>)}{organization.subscriptionPeriodEventsCountExceededAt &&- organization.isActive && (+ organization.isActive &&+ organization.isExceeded && (<Alerttitle="Events limit exceeded"description={`Your subscription has exceeded the limit on ${format(organization.subscriptionPeriodEventsCountExceededAt, 'PPP')}`}diff --git a/apps/worker/src/jobs/sessions.ts b/apps/worker/src/jobs/sessions.tsindex 632e33a21..c16c63edc 100644--- a/apps/worker/src/jobs/sessions.ts+++ b/apps/worker/src/jobs/sessions.ts@@ -57,16 +57,22 @@ const updateEventsCount = cacheable(async function updateEventsCount(}if (organizationEventsCount) {+ // Self-hosting has no billing/event limits. Never flag the org as+ // exceeded, and clear any stale flag that was set before this guard+ // existed (default limit is 0, which otherwise trips on the first event).+ const isSelfHosted = process.env.SELF_HOSTED === 'true';+await db.organization.update({where: {id: organization.id,},data: {subscriptionPeriodEventsCount: organizationEventsCount,- subscriptionPeriodEventsCountExceededAt:- organizationEventsCount >- organization.subscriptionPeriodEventsLimit &&- !organization.subscriptionPeriodEventsCountExceededAt+ subscriptionPeriodEventsCountExceededAt: isSelfHosted+ ? null+ : organizationEventsCount >+ organization.subscriptionPeriodEventsLimit &&+ !organization.subscriptionPeriodEventsCountExceededAt? new Date(): organizationEventsCount <=organization.subscriptionPeriodEventsLimit