فهرست منبع

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

Hendrik Depauw 4 سال پیش
والد
کامیت
76361d5165
1فایلهای تغییر یافته به همراه7 افزوده شده و 5 حذف شده
  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);
 
                 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'],
                     });
-                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);
                     job.setProgress(Math.ceil((++completed / job.data.collectionIds.length) * 100));
                     this.eventBus.publish(