From 801f859c16abb8c4000e744ee4d3cf68d59c2cab Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 28 Aug 2024 18:58:25 +0200 Subject: [PATCH] fix: prevent deadlocks from happening by using the native deleteMany service --- .changeset/chilly-melons-sneeze.md | 5 +++++ .../core/server/admin-api/services/bulk-generate.ts | 4 ++-- .../core/server/content-api/services/url-alias.ts | 13 +------------ 3 files changed, 8 insertions(+), 14 deletions(-) create mode 100644 .changeset/chilly-melons-sneeze.md diff --git a/.changeset/chilly-melons-sneeze.md b/.changeset/chilly-melons-sneeze.md new file mode 100644 index 00000000..2251730c --- /dev/null +++ b/.changeset/chilly-melons-sneeze.md @@ -0,0 +1,5 @@ +--- +"@pluginpal/webtools-core": patch +--- + +Prevent deadlocks from happening by using the native deleteMany service diff --git a/packages/core/server/admin-api/services/bulk-generate.ts b/packages/core/server/admin-api/services/bulk-generate.ts index 1ff2da72..0705647d 100644 --- a/packages/core/server/admin-api/services/bulk-generate.ts +++ b/packages/core/server/admin-api/services/bulk-generate.ts @@ -79,7 +79,7 @@ const generateUrlAliases = async (parms: GenerateParams) => { await Promise.all(types.map(async (type) => { if (generationType === 'all') { // Delete all the URL aliases for the given type. - await getPluginService('url-alias').deleteMany({ + await strapi.entityService.deleteMany('plugin::webtools.url-alias', { // @ts-ignore locale: 'all', filters: { @@ -90,7 +90,7 @@ const generateUrlAliases = async (parms: GenerateParams) => { if (generationType === 'only_generated') { // Delete all the auto generated URL aliases of the given type. - await getPluginService('url-alias').deleteMany({ + await strapi.entityService.deleteMany('plugin::webtools.url-alias', { // @ts-ignore locale: 'all', filters: { diff --git a/packages/core/server/content-api/services/url-alias.ts b/packages/core/server/content-api/services/url-alias.ts index b8495c88..d758f90d 100644 --- a/packages/core/server/content-api/services/url-alias.ts +++ b/packages/core/server/content-api/services/url-alias.ts @@ -1,5 +1,4 @@ import { factories } from '@strapi/strapi'; -import { EntityService, Common } from '@strapi/types'; /** * URL alias service @@ -7,14 +6,4 @@ import { EntityService, Common } from '@strapi/types'; const contentTypeSlug = 'plugin::webtools.url-alias'; -export default factories.createCoreService(contentTypeSlug, ({ strapi }) => ({ - deleteMany: async (params: EntityService.Params.Pick) => { - const toBeDeletedEntities = await strapi.entityService.findMany(contentTypeSlug, params); - - await Promise.all(toBeDeletedEntities.map(async (entity) => { - await strapi.entityService.delete(contentTypeSlug, entity.id); - })); - - return true; - }, -})); +export default factories.createCoreService(contentTypeSlug);