Skip to content

Commit e342f47

Browse files
committed
fix: cap events count to max int4
1 parent da95f4c commit e342f47

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/worker/src/jobs/sessions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
import { cacheable } from '@openpanel/redis';
1212
import { createSessionEnd } from './events.create-session-end';
1313

14+
const INT4_MAX = 2_147_483_647;
15+
1416
export async function sessionsJob(job: Job<SessionsQueuePayload>) {
1517
const res = await createSessionEnd(job);
1618
try {
@@ -51,7 +53,10 @@ const updateEventsCount = cacheable(async function updateEventsCount(
5153
id: projectId,
5254
},
5355
data: {
54-
eventsCount: projectEventsCount,
56+
// Saturating counter: the column is INT4 and lifetime counts can
57+
// exceed it. It's only used as a sort key and activity threshold,
58+
// never for billing, so clamping is safe.
59+
eventsCount: Math.min(projectEventsCount, INT4_MAX),
5560
},
5661
});
5762
}
@@ -67,7 +72,10 @@ const updateEventsCount = cacheable(async function updateEventsCount(
6772
id: organization.id,
6873
},
6974
data: {
70-
subscriptionPeriodEventsCount: organizationEventsCount,
75+
subscriptionPeriodEventsCount: Math.min(
76+
organizationEventsCount,
77+
INT4_MAX,
78+
),
7179
subscriptionPeriodEventsCountExceededAt: isSelfHosted
7280
? null
7381
: organizationEventsCount >

0 commit comments

Comments
 (0)