mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 01:28:07 +00:00
update/create/delete components sequentially instead of in parallel
This commit is contained in:
parent
fafdaa4e11
commit
e295276048
@ -43,9 +43,12 @@ const createComponents = async (uid, data) => {
|
|||||||
throw new Error('Expected an array to create repeatable component');
|
throw new Error('Expected an array to create repeatable component');
|
||||||
}
|
}
|
||||||
|
|
||||||
const components = await Promise.all(
|
// No Promise.all to avoid deadlocks
|
||||||
componentValue.map((value) => createComponent(componentUID, value))
|
const components = [];
|
||||||
);
|
for (const value of componentValue) {
|
||||||
|
const compo = await createComponent(componentUID, value);
|
||||||
|
components.push(compo);
|
||||||
|
}
|
||||||
|
|
||||||
componentBody[attributeName] = components.map(({ id }) => {
|
componentBody[attributeName] = components.map(({ id }) => {
|
||||||
return {
|
return {
|
||||||
@ -77,18 +80,18 @@ const createComponents = async (uid, data) => {
|
|||||||
throw new Error('Expected an array to create repeatable component');
|
throw new Error('Expected an array to create repeatable component');
|
||||||
}
|
}
|
||||||
|
|
||||||
componentBody[attributeName] = await Promise.all(
|
// No Promise.all to avoid deadlocks
|
||||||
dynamiczoneValues.map(async (value) => {
|
componentBody[attributeName] = [];
|
||||||
|
for (const value of dynamiczoneValues) {
|
||||||
const { id } = await createComponent(value.__component, value);
|
const { id } = await createComponent(value.__component, value);
|
||||||
return {
|
componentBody[attributeName].push({
|
||||||
id,
|
id,
|
||||||
__component: value.__component,
|
__component: value.__component,
|
||||||
__pivot: {
|
__pivot: {
|
||||||
field: attributeName,
|
field: attributeName,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
})
|
}
|
||||||
);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -137,9 +140,12 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|||||||
throw new Error('Expected an array to create repeatable component');
|
throw new Error('Expected an array to create repeatable component');
|
||||||
}
|
}
|
||||||
|
|
||||||
const components = await Promise.all(
|
// No Promise.all to avoid deadlocks
|
||||||
componentValue.map((value) => updateOrCreateComponent(componentUID, value))
|
const components = [];
|
||||||
);
|
for (const value of componentValue) {
|
||||||
|
const compo = await updateOrCreateComponent(componentUID, value);
|
||||||
|
components.push(compo);
|
||||||
|
}
|
||||||
|
|
||||||
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
|
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
|
||||||
return {
|
return {
|
||||||
@ -173,19 +179,18 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|||||||
throw new Error('Expected an array to create repeatable component');
|
throw new Error('Expected an array to create repeatable component');
|
||||||
}
|
}
|
||||||
|
|
||||||
componentBody[attributeName] = await Promise.all(
|
// No Promise.all to avoid deadlocks
|
||||||
dynamiczoneValues.map(async (value) => {
|
componentBody[attributeName] = [];
|
||||||
|
for (const value of dynamiczoneValues) {
|
||||||
const { id } = await updateOrCreateComponent(value.__component, value);
|
const { id } = await updateOrCreateComponent(value.__component, value);
|
||||||
|
componentBody[attributeName].push({
|
||||||
return {
|
|
||||||
id,
|
id,
|
||||||
__component: value.__component,
|
__component: value.__component,
|
||||||
__pivot: {
|
__pivot: {
|
||||||
field: attributeName,
|
field: attributeName,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
})
|
}
|
||||||
);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -287,14 +292,14 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
|||||||
|
|
||||||
if (attribute.type === 'component') {
|
if (attribute.type === 'component') {
|
||||||
const { component: componentUID } = attribute;
|
const { component: componentUID } = attribute;
|
||||||
await Promise.all(
|
for (const subValue of _.castArray(value)) {
|
||||||
_.castArray(value).map((subValue) => deleteComponent(componentUID, subValue))
|
await deleteComponent(componentUID, subValue);
|
||||||
);
|
}
|
||||||
} else {
|
} else {
|
||||||
// delete dynamic zone components
|
// delete dynamic zone components
|
||||||
await Promise.all(
|
for (const subValue of _.castArray(value)) {
|
||||||
_.castArray(value).map((subValue) => deleteComponent(subValue.__component, subValue))
|
await deleteComponent(subValue.__component, subValue);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user