OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
feat(cohorts): make the materialize limit configurable via env (#440)
Ritik Jainf2e79a7b031d
diff --git a/packages/db/src/services/cohort.service.ts b/packages/db/src/services/cohort.service.tsindex 0e0beafac..ff2c005cb 100644--- a/packages/db/src/services/cohort.service.ts+++ b/packages/db/src/services/cohort.service.ts@@ -24,7 +24,25 @@ import {type IServiceProfile,} from './profile.service';-export const COHORT_MATERIALIZE_LIMIT = 10000;+// Max members materialized into cohort_members per compute. Cohorts larger+// than this are silently truncated to an arbitrary subset, so deployments+// with bigger cohorts need to raise it — env-tunable to avoid an image+// rebuild for what is really a sizing knob.+//+// Strictly a positive safe integer: anything else falls back to the+// default. Number.parseInt would accept '5000junk' or '-1' (LIMIT -1 is a+// query error), and 0 is falsy at the `limit ? LIMIT ... : ''` call sites,+// which would silently remove the cap entirely.+const COHORT_MATERIALIZE_LIMIT_RAW = process.env.COHORT_MATERIALIZE_LIMIT;+const COHORT_MATERIALIZE_LIMIT_PARSED =+ COHORT_MATERIALIZE_LIMIT_RAW && /^\d+$/.test(COHORT_MATERIALIZE_LIMIT_RAW)+ ? Number(COHORT_MATERIALIZE_LIMIT_RAW)+ : Number.NaN;+export const COHORT_MATERIALIZE_LIMIT =+ Number.isSafeInteger(COHORT_MATERIALIZE_LIMIT_PARSED) &&+ COHORT_MATERIALIZE_LIMIT_PARSED > 0+ ? COHORT_MATERIALIZE_LIMIT_PARSED+ : 10000;function buildTimeConstraint(timeframe: Timeframe): string {if (timeframe.type === 'relative') {