Browse Source

perf(core): Reduce memory usage of apply-collection-filters job

Hendrik Depauw 4 years ago
parent
commit
76361d5165
1 changed files with 7 additions and 5 deletions
  1. 7 5
      packages/core/src/service/services/collection.service.ts

+ 7 - 5
packages/core/src/service/services/collection.service.ts

@@ -85,13 +85,15 @@ export class CollectionService implements OnModuleInit {
                 const ctx = RequestContext.deserialize(job.data.ctx);
                 const ctx = RequestContext.deserialize(job.data.ctx);
 
 
                 Logger.verbose(`Processing ${job.data.collectionIds.length} Collections`);
                 Logger.verbose(`Processing ${job.data.collectionIds.length} Collections`);
-                const collections = await this.connection
-                    .getRepository(Collection)
-                    .findByIds(job.data.collectionIds, {
+                let completed = 0;
+                for (const collectionId of job.data.collectionIds) {
+                    const collection = await this.connection.getRepository(Collection).findOne(collectionId, {
                         relations: ['productVariants'],
                         relations: ['productVariants'],
                     });
                     });
-                let completed = 0;
-                for (const collection of collections) {
+                    if (!collection) {
+                        Logger.warn(`Could not find Collection with id ${collectionId}, skipping`);
+                        continue;
+                    }
                     const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
                     const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
                     job.setProgress(Math.ceil((++completed / job.data.collectionIds.length) * 100));
                     job.setProgress(Math.ceil((++completed / job.data.collectionIds.length) * 100));
                     this.eventBus.publish(
                     this.eventBus.publish(