Skip to content

Commit

Permalink
fix: increase the batch size of operation usage insertion (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
JivusAyrus authored Nov 15, 2024
1 parent ba9acaf commit 44ac8a8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions controlplane/src/core/repositories/SchemaCheckRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { and, eq, inArray, or, sql } from 'drizzle-orm';
import _ from 'lodash';
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import { VCSContext } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import pLimit from 'p-limit';
import { NewSchemaChangeOperationUsage } from '../../db/models.js';
import * as schema from '../../db/schema.js';
import {
Expand Down Expand Up @@ -98,6 +99,7 @@ export class SchemaCheckRepository {
federatedGraphId: string,
) {
const values: NewSchemaChangeOperationUsage[] = [];
const limit = pLimit(10);

for (const [schemaCheckChangeActionId, operations] of schemaCheckActionOperations.entries()) {
values.push(
Expand All @@ -121,11 +123,14 @@ export class SchemaCheckRepository {
return;
}

const arrayOfValues: NewSchemaChangeOperationUsage[][] = createBatches<NewSchemaChangeOperationUsage>(values, 500);
const arrayOfValues: NewSchemaChangeOperationUsage[][] = createBatches<NewSchemaChangeOperationUsage>(values, 1000);
const promises = [];

for (const values of arrayOfValues) {
await this.db.insert(schemaCheckChangeActionOperationUsage).values(values).execute();
promises.push(limit(() => this.db.insert(schemaCheckChangeActionOperationUsage).values(values).execute()));
}

await Promise.all(promises);
}

private mapChangesFromDriverValue = (val: any) => {
Expand Down

0 comments on commit 44ac8a8

Please sign in to comment.