tada5hi/typeorm-extension

Bug: useSeederFactory(Entity).saveMany(n) saves entities slowly

Closed this issue ยท 2 comments

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.

good catch!

๐ŸŽ‰ This issue has been resolved in version 3.5.1 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€