diff --git a/packages/cli/src/databases/repositories/workflow.repository.ts b/packages/cli/src/databases/repositories/workflow.repository.ts index 5dcd369def9c6..393e4948c9121 100644 --- a/packages/cli/src/databases/repositories/workflow.repository.ts +++ b/packages/cli/src/databases/repositories/workflow.repository.ts @@ -45,10 +45,12 @@ export class WorkflowRepository extends Repository { }); } - async getActiveIds() { + async getActiveIds({ maxResults }: { maxResults?: number } = {}) { const activeWorkflows = await this.find({ select: ['id'], where: { active: true }, + // 'take' and 'order' are only needed when maxResults is provided: + ...(maxResults ? { take: maxResults, order: { createdAt: 'ASC' } } : {}), }); return activeWorkflows.map((workflow) => workflow.id); } diff --git a/packages/cli/src/metrics/license-metrics.service.ts b/packages/cli/src/metrics/license-metrics.service.ts index 338fa70a3e72a..b8fea3b29f330 100644 --- a/packages/cli/src/metrics/license-metrics.service.ts +++ b/packages/cli/src/metrics/license-metrics.service.ts @@ -37,7 +37,9 @@ export class LicenseMetricsService { async collectPassthroughData() { return { - activeWorkflowIds: await this.workflowRepository.getActiveIds(), + // Get only the first 1000 active workflow IDs to avoid sending too much data to License Server + // Passthrough data is forwarded to Telemetry for further analysis, such as quota excesses + activeWorkflowIds: await this.workflowRepository.getActiveIds({ maxResults: 1000 }), }; } } diff --git a/packages/cli/test/integration/database/repositories/workflow.repository.test.ts b/packages/cli/test/integration/database/repositories/workflow.repository.test.ts index acff2cbce9738..2092de97e6177 100644 --- a/packages/cli/test/integration/database/repositories/workflow.repository.test.ts +++ b/packages/cli/test/integration/database/repositories/workflow.repository.test.ts @@ -73,7 +73,7 @@ describe('WorkflowRepository', () => { }); describe('getActiveIds', () => { - it('should return active workflow IDs', async () => { + it('should return all active workflow IDs when invoked without maxResults', async () => { // // ARRANGE // @@ -92,6 +92,28 @@ describe('WorkflowRepository', () => { // ASSERT // expect(activeIds).toEqual([workflows[0].id]); + expect(activeIds).toHaveLength(1); + }); + + it('should return a capped number of active workflow IDs when invoked with maxResults', async () => { + // + // ARRANGE + // + await Promise.all([ + createWorkflow({ active: true }), + createWorkflow({ active: false }), + createWorkflow({ active: true }), + ]); + + // + // ACT + // + const activeIds = await Container.get(WorkflowRepository).getActiveIds({ maxResults: 1 }); + + // + // ASSERT + // + expect(activeIds).toHaveLength(1); }); }); });