Skip to content

Commit

Permalink
perf(core): Improve performance of apply-collection-filters job
Browse files Browse the repository at this point in the history
  • Loading branch information
dkostenko-jsninja committed Jun 2, 2021
1 parent d130134 commit 3c49c5e
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/core/src/service/services/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export class CollectionService implements OnModuleInit {
Logger.verbose(`Processing ${job.data.collectionIds.length} Collections`);
let completed = 0;
for (const collectionId of job.data.collectionIds) {
const collection = await this.connection.getRepository(Collection).findOne(collectionId, {
relations: ['productVariants'],
});
const collection = await this.connection.getRepository(Collection).findOne(collectionId);
if (!collection) {
Logger.warn(`Could not find Collection with id ${collectionId}, skipping`);
continue;
Expand Down Expand Up @@ -476,16 +474,14 @@ export class CollectionService implements OnModuleInit {
* Returns the IDs of the Collection's ProductVariants.
*/
async getCollectionProductVariantIds(collection: Collection, ctx?: RequestContext): Promise<ID[]> {
if (collection.productVariants) {
return collection.productVariants.map(v => v.id);
} else {
const productVariants = await this.connection
.getRepository(ctx, ProductVariant)
.createQueryBuilder('variant')
.innerJoin('variant.collections', 'collection', 'collection.id = :id', { id: collection.id })
.getMany();
return productVariants.map(v => v.id);
}
const productVariants = await this.connection
.getRepository(ctx, ProductVariant)
.createQueryBuilder('variant')
.select('variant.id')
.innerJoin('variant.collections', 'collection', 'collection.id = :id', { id: collection.id })
.getRawMany();

return productVariants.map(v => v.variant_id);
}

/**
Expand Down

0 comments on commit 3c49c5e

Please sign in to comment.