From d89274b625b7c7266a6650744f9e0ba438b38623 Mon Sep 17 00:00:00 2001 From: Dominic Robinson <dominic@dcrdev.com> Date: Fri, 9 Dec 2022 15:38:12 +0000 Subject: [PATCH 1/3] refactor(api-plugin-products): use size to determine empty ancestors Signed-off-by: Dominic Robinson <dominic@dcrdev.com> --- packages/api-plugin-products/src/utils/applyProductFilters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-plugin-products/src/utils/applyProductFilters.js b/packages/api-plugin-products/src/utils/applyProductFilters.js index 5bcc1862644..e48d5e864c1 100644 --- a/packages/api-plugin-products/src/utils/applyProductFilters.js +++ b/packages/api-plugin-products/src/utils/applyProductFilters.js @@ -103,7 +103,7 @@ export default function applyProductFilters(context, productFilters) { // Init default selector - Everyone can see products that fit this selector let selector = { - ancestors: [], // Lookup top-level products + ancestors: { $size: 0 }, // Lookup top-level products isDeleted: { $ne: true } // by default, we don't publish deleted products }; From fbe07828dc57e29b63d878604305ed51411f7ddc Mon Sep 17 00:00:00 2001 From: Dominic Robinson <dominic@dcrdev.com> Date: Fri, 9 Dec 2022 15:39:26 +0000 Subject: [PATCH 2/3] refactor(api-plugin-products): add ancestors to compound indexes Signed-off-by: Dominic Robinson <dominic@dcrdev.com> --- packages/api-plugin-products/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-plugin-products/src/index.js b/packages/api-plugin-products/src/index.js index 0041898cec5..e249e40e452 100644 --- a/packages/api-plugin-products/src/index.js +++ b/packages/api-plugin-products/src/index.js @@ -33,8 +33,8 @@ export default async function register(app) { [{ hashtags: 1 }, { name: "c2_hashtags" }], [{ shopId: 1 }, { name: "c2_shopId" }], [{ "workflow.status": 1 }, { name: "c2_workflow.status" }], - [{ createdAt: 1, shopId: 1 }, { name: "c2_createdAt_shopId" }], - [{ updatedAt: 1, shopId: 1 }, { name: "c2_updatedAt_shopId" }], + [{ createdAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_createdAt_shopId" }], + [{ updatedAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_updatedAt_shopId" }], // Use _id as second sort to force full stability [{ updatedAt: 1, _id: 1 }] ] From a4f9b08d22a2c4042307f17f996d32e61baae30e Mon Sep 17 00:00:00 2001 From: Dominic Robinson <dominic@dcrdev.com> Date: Fri, 9 Dec 2022 23:00:26 +0000 Subject: [PATCH 3/3] chore(api-plugin-products): rename ancestors compound indexes --- packages/api-plugin-products/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-plugin-products/src/index.js b/packages/api-plugin-products/src/index.js index e249e40e452..b66b1e1172d 100644 --- a/packages/api-plugin-products/src/index.js +++ b/packages/api-plugin-products/src/index.js @@ -33,8 +33,8 @@ export default async function register(app) { [{ hashtags: 1 }, { name: "c2_hashtags" }], [{ shopId: 1 }, { name: "c2_shopId" }], [{ "workflow.status": 1 }, { name: "c2_workflow.status" }], - [{ createdAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_createdAt_shopId" }], - [{ updatedAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_updatedAt_shopId" }], + [{ createdAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_createdAt_shopId_ancestors" }], + [{ updatedAt: 1, shopId: 1, ancestors: 1 }, { name: "c2_updatedAt_shopId_ancestors" }], // Use _id as second sort to force full stability [{ updatedAt: 1, _id: 1 }] ]