From 8bc723c641e53e091108e5bbffa72b1a09223820 Mon Sep 17 00:00:00 2001 From: Princi Vershwal Date: Wed, 4 Dec 2024 13:35:29 +0530 Subject: [PATCH] Removed unnecessary forUpdate from linkSubscription method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://linear.app/ghost/issue/ENG-1758/product-row-locking-in-linksubscription-causes-slowness-in-high-signup - The method used a FOR UPDATE query when fetching the Ghost product despite never updating that row. - In this case, we're only reading the default product to link it with a subscription - we're not actually modifying the default product itself. The operation is read-only in nature, therefore, the forUpdate lock is unnecessary - The actual update to the product happens later in the code when we call this._productRepository.update() with the stripe price data, and that operation has its own transaction handling and locking mechanisms --- ghost/members-api/lib/repositories/MemberRepository.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghost/members-api/lib/repositories/MemberRepository.js b/ghost/members-api/lib/repositories/MemberRepository.js index c54d55de4d..ada94f69cf 100644 --- a/ghost/members-api/lib/repositories/MemberRepository.js +++ b/ghost/members-api/lib/repositories/MemberRepository.js @@ -944,7 +944,7 @@ module.exports = class MemberRepository { const subscriptionPriceData = _.get(subscription, 'items.data[0].price'); let ghostProduct; try { - ghostProduct = await this._productRepository.get({stripe_product_id: subscriptionPriceData.product}, {...options, forUpdate: true}); + ghostProduct = await this._productRepository.get({stripe_product_id: subscriptionPriceData.product}, options); // Use first Ghost product as default product in case of missing link if (!ghostProduct) { ghostProduct = await this._productRepository.getDefaultProduct({