fix(core): Reduce payload of license renewal calls (no-changelog) (#12236)

This commit is contained in:
Cornelius Suermann 2025-01-17 17:59:28 +01:00 committed by GitHub
parent 2c9b690010
commit de49182652
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 3 deletions

View file

@ -44,10 +44,12 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
});
}
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);
}

View file

@ -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 }),
};
}
}

View file

@ -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);
});
});
});