File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import {
1111import { cacheable } from '@openpanel/redis' ;
1212import { createSessionEnd } from './events.create-session-end' ;
1313
14+ const INT4_MAX = 2_147_483_647 ;
15+
1416export 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 >
You can’t perform that action at this time.
0 commit comments