diff --git a/packages/core-assortments/src/module/configureAssortmentsModule.ts b/packages/core-assortments/src/module/configureAssortmentsModule.ts index da35c92c1e..b188930223 100644 --- a/packages/core-assortments/src/module/configureAssortmentsModule.ts +++ b/packages/core-assortments/src/module/configureAssortmentsModule.ts @@ -466,7 +466,7 @@ export const configureAssortmentsModule = async ({ await emit('ASSORTMENT_UPDATE', { assortmentId }); if (!options?.skipInvalidation) { - invalidateCache({ assortmentIds: [assortmentId] }); + await invalidateCache({ assortmentIds: [assortmentId] }); } return assortmentId; }, diff --git a/packages/core-filters/src/module/configureFilterSearchModule.ts b/packages/core-filters/src/module/configureFilterSearchModule.ts index 116116a96b..0876fe54a5 100644 --- a/packages/core-filters/src/module/configureFilterSearchModule.ts +++ b/packages/core-filters/src/module/configureFilterSearchModule.ts @@ -128,17 +128,12 @@ export const configureFilterSearchModule = ({ return leftIndex - rightIndex; }); - const relevantProducts = await modules.products.findProducts( - { - productSelector, - productIds: totalProductIds, - includeDrafts: searchQuery.includeInactive, - }, - { - projection: { _id: 1 }, - }, - ); - const relevantProductIds = relevantProducts.map(({ _id }) => _id); + const relevantProductIds = await modules.products.findProductIds({ + productSelector, + productIds: totalProductIds, + includeDrafts: searchQuery.includeInactive, + }); + return Promise.all( sortedFilters.map(async (filter) => { return loadFilter( diff --git a/packages/core-filters/src/module/configureFiltersModule.ts b/packages/core-filters/src/module/configureFiltersModule.ts index a941d98c72..2f1c31b318 100644 --- a/packages/core-filters/src/module/configureFiltersModule.ts +++ b/packages/core-filters/src/module/configureFiltersModule.ts @@ -130,19 +130,10 @@ export const configureFiltersModule = async ({ ); if (!productSelector) return []; - const products = await modules.products.findProducts( - { - productSelector, - includeDrafts: true, - sort: [], - offset: 0, - limit: 0, - }, - { - projection: { _id: true }, - }, - ); - return products.map(({ _id }) => _id); + return modules.products.findProductIds({ + productSelector, + includeDrafts: true, + }); }; const buildProductIdMap = async ( diff --git a/packages/core-products/src/module/configureProductsModule.ts b/packages/core-products/src/module/configureProductsModule.ts index f50ef5888f..ec9c40e4be 100644 --- a/packages/core-products/src/module/configureProductsModule.ts +++ b/packages/core-products/src/module/configureProductsModule.ts @@ -445,12 +445,13 @@ export const configureProductsModule = async ({ return Products.findOne(selector, {}); }, - findProducts: async ({ limit, offset, sort, ...query }) => { + findProducts: async ({ limit, offset, sort, ...query }, options) => { const defaultSortOption: Array = [ { key: 'sequence', value: SortDirection.ASC }, { key: 'published', value: SortDirection.DESC }, ]; const products = Products.find(buildFindSelector(query), { + ...(options || {}), limit, skip: offset, sort: buildSortOptions(sort || defaultSortOption), @@ -458,6 +459,10 @@ export const configureProductsModule = async ({ return products.toArray(); }, + findProductIds: async (query) => { + return Products.distinct('_id', buildFindSelector(query)); + }, + count: async (query) => { return Products.countDocuments(buildFindSelector(query)); }, diff --git a/packages/plugins/src/worker/zombie-killer.ts b/packages/plugins/src/worker/zombie-killer.ts index 74795359ed..9d76161d06 100644 --- a/packages/plugins/src/worker/zombie-killer.ts +++ b/packages/plugins/src/worker/zombie-killer.ts @@ -53,11 +53,7 @@ export const ZombieKillerWorker: IWorkerAdapter< }); // Remove unreferenced product entities - const products = await modules.products.findProducts( - { includeDrafts: true }, - { projection: { _id: 1 } }, - ); - const productIds = products.map((a) => a._id); + const productIds = await modules.products.findProductIds({ includeDrafts: true }); const deletedProductTextsCount = await modules.products.texts.deleteMany({ excludedProductIds: productIds, });