add createMany fields to fieldMetadataService to batch field creation (#9957)

## Context
Not exposed in the API yet, this new method allows us to reduce the time
to create multiple fields at once, mostly during seeding. This allows us
to batch transactions and avoid recomputing the cache everytime.

With this change, we recompute the cache 7 times instead of 35 during
seeding. We could do the same for objects.
This commit is contained in:
Weiko
2025-02-04 11:18:57 +01:00
committed by GitHub
parent 0e5c2cff42
commit 40f43a4076
3 changed files with 297 additions and 200 deletions

View File

@ -265,13 +265,12 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
workspaceId,
);
for (const customField of DEV_SEED_COMPANY_CUSTOM_FIELDS) {
// TODO: Use createMany once implemented for better performances
await this.fieldMetadataService.createOne({
await this.fieldMetadataService.createMany(
DEV_SEED_COMPANY_CUSTOM_FIELDS.map((customField) => ({
...customField,
isCustom: true,
});
}
})),
);
}
async seedPeopleCustomFields(
@ -289,11 +288,11 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
workspaceId,
);
for (const customField of DEV_SEED_PERSON_CUSTOM_FIELDS) {
await this.fieldMetadataService.createOne({
await this.fieldMetadataService.createMany(
DEV_SEED_PERSON_CUSTOM_FIELDS.map((customField) => ({
...customField,
isCustom: true,
});
}
})),
);
}
}