Browse Source

perf(core): Optimize query to fetch all collection ids on changes

Michael Bromley 3 years ago
parent
commit
a362fb487d
1 changed files with 5 additions and 1 deletions
  1. 5 1
      packages/core/src/service/services/collection.service.ts

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

@@ -89,7 +89,11 @@ export class CollectionService implements OnModuleInit {
         merge(productEvents$, variantEvents$)
             .pipe(debounceTime(50))
             .subscribe(async event => {
-                const collections = await this.connection.getRepository(Collection).find();
+                const collections = await this.connection
+                    .getRepository(Collection)
+                    .createQueryBuilder('collection')
+                    .select('collection.id', 'id')
+                    .getRawMany();
                 await this.applyFiltersQueue.add({
                     ctx: event.ctx.serialize(),
                     collectionIds: collections.map(c => c.id),