Skip to content

Commit

Permalink
Merge pull request #188 from pluginpal/feature/prevent-deadlock
Browse files Browse the repository at this point in the history
fix: prevent deadlocks from happening by using the native deleteMany …
  • Loading branch information
boazpoolman authored Sep 1, 2024
2 parents de693c7 + 801f859 commit 82cbcca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-melons-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pluginpal/webtools-core": patch
---

Prevent deadlocks from happening by using the native deleteMany service
4 changes: 2 additions & 2 deletions packages/core/server/admin-api/services/bulk-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
13 changes: 1 addition & 12 deletions packages/core/server/content-api/services/url-alias.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { factories } from '@strapi/strapi';
import { EntityService, Common } from '@strapi/types';

/**
* URL alias service
*/

const contentTypeSlug = 'plugin::webtools.url-alias';

export default factories.createCoreService(contentTypeSlug, ({ strapi }) => ({
deleteMany: async (params: EntityService.Params.Pick<Common.UID.ContentType, 'filters'>) => {
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);

0 comments on commit 82cbcca

Please sign in to comment.