OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: cap events count to max int4
Carl-Gerhard Lindesvärde342f475c47e
diff --git a/apps/worker/src/jobs/sessions.ts b/apps/worker/src/jobs/sessions.tsindex c16c63edc..d41303ae6 100644--- a/apps/worker/src/jobs/sessions.ts+++ b/apps/worker/src/jobs/sessions.ts@@ -11,6 +11,8 @@ import {import { cacheable } from '@openpanel/redis';import { createSessionEnd } from './events.create-session-end';+const INT4_MAX = 2_147_483_647;+export async function sessionsJob(job: Job<SessionsQueuePayload>) {const res = await createSessionEnd(job);try {@@ -51,7 +53,10 @@ const updateEventsCount = cacheable(async function updateEventsCount(id: projectId,},data: {- eventsCount: projectEventsCount,+ // Saturating counter: the column is INT4 and lifetime counts can+ // exceed it. It's only used as a sort key and activity threshold,+ // never for billing, so clamping is safe.+ eventsCount: Math.min(projectEventsCount, INT4_MAX),},});}@@ -67,7 +72,10 @@ const updateEventsCount = cacheable(async function updateEventsCount(id: organization.id,},data: {- subscriptionPeriodEventsCount: organizationEventsCount,+ subscriptionPeriodEventsCount: Math.min(+ organizationEventsCount,+ INT4_MAX,+ ),subscriptionPeriodEventsCountExceededAt: isSelfHosted? null: organizationEventsCount >