Skip to content

Commit

Permalink
fix: max call stack reached while inserting operation usage of checks (
Browse files Browse the repository at this point in the history
…#1338)

Co-authored-by: Dustin Deus <deusdustin@gmail.com>
  • Loading branch information
JivusAyrus and StarpTech authored Nov 7, 2024
1 parent fc077ff commit a3fd3d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controlplane/src/core/repositories/SchemaCheckRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { ComposedFederatedGraph } from '../composition/composer.js';
import { SchemaDiff } from '../composition/schemaCheck.js';
import { InspectorOperationResult } from '../services/SchemaUsageTrafficInspector.js';
import { createBatches } from '../util.js';
import { FederatedGraphConfig } from './FederatedGraphRepository.js';

export class SchemaCheckRepository {
Expand Down Expand Up @@ -120,7 +121,11 @@ export class SchemaCheckRepository {
return;
}

await this.db.insert(schemaCheckChangeActionOperationUsage).values(values).execute();
const arrayOfValues: NewSchemaChangeOperationUsage[][] = createBatches<NewSchemaChangeOperationUsage>(values, 500);

for (const values of arrayOfValues) {
await this.db.insert(schemaCheckChangeActionOperationUsage).values(values).execute();
}
}

private mapChangesFromDriverValue = (val: any) => {
Expand Down
11 changes: 11 additions & 0 deletions controlplane/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,14 @@ export function mergeUrls(baseUrl: string, relativeUrl: string) {

return new URL(relativeUrl, baseUrl).toString();
}

export function createBatches<T>(array: T[], batchSize: number): T[][] {
const batches: T[][] = [];

for (let i = 0; i < array.length; i += batchSize) {
const batch = array.slice(i, i + batchSize);
batches.push(batch);
}

return batches;
}

0 comments on commit a3fd3d9

Please sign in to comment.