Skip to content

Commit

Permalink
perf: opimized seeder-factory save-many fn (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi authored Apr 9, 2024
1 parent 4ccb4b6 commit a4dfce5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/seeder/factory/module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { FakerOptions, LocaleDefinition } from '@faker-js/faker';
import { Faker } from '@faker-js/faker';
import type { SaveOptions } from 'typeorm';
import { isObject, load } from 'locter';
import type { SeederFactoryContext } from './type';
import { hasOwnProperty, isPromise } from '../../utils';
import type { SaveOptions } from 'typeorm';
import { useDataSource } from '../../data-source';
import { hasOwnProperty, isPromise } from '../../utils';
import type { SeederFactoryContext } from './type';

export class SeederFactory<O extends Record<string, any>, Meta = unknown> {
public readonly context: SeederFactoryContext<O, Meta>;
Expand Down Expand Up @@ -78,13 +78,13 @@ export class SeederFactory<O extends Record<string, any>, Meta = unknown> {
params?: Partial<O>,
options?: SaveOptions,
) : Promise<O[]> {
const items : O[] = [];
const promises : Promise<O>[] = [];
for (let i = 0; i < amount; i++) {
const item = await this.save(params, options);
items.push(item);
const item = this.save(params, options);
promises.push(item);
}

return items;
return Promise.all(promises);
}

// --------------------------------------------------------------
Expand Down

0 comments on commit a4dfce5

Please sign in to comment.