Bug: useSeederFactory(Entity).saveMany(n) saves entities slowly
Closed this issue ยท 2 comments
arthurgubaidullin commented
Within the for loop, await is used, which makes the entire loop sequential.
Versions
- Node: v20.11.0
- OS: linux, mac
Reproduction
Steps to reproduce
await useSeederFactory(Entity).saveMany(1000);
Problem in file.
What is Expected?
I expect the entities to persist in parallel.
What is actually happening?
Entities are stored sequentially.
Solution
public async saveMany(
amount: number,
params?: Partial<O>,
options?: SaveOptions,
) : Promise<O[]> {
const items : Promise<O>[] = [];
for (let i = 0; i < amount; i++) {
const item = this.save(params, options);
items.push(item);
}
return Promise.all(items);
}
P.S.
Unfortunately, I can't make the changes myself as the tests are constantly flicking.
tada5hi commented
good catch!
github-actions commented
๐ This issue has been resolved in version 3.5.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐