Skip to content

Commit

Permalink
use sequential update for locales and components
Browse files Browse the repository at this point in the history
  • Loading branch information
petersg83 committed Jan 23, 2023
1 parent 62e3f93 commit c02061d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
75 changes: 39 additions & 36 deletions packages/core/strapi/lib/services/entity-service/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ const createComponents = async (uid, data) => {
throw new Error('Expected an array to create repeatable component');
}

const components = await Promise.all(
componentValue.map((value) => createComponent(componentUID, value))
);
const components = [];
for (const value of componentValue) {
components.push(await createComponent(componentUID, value));
}

componentBody[attributeName] = components.map(({ id }) => {
return {
Expand Down Expand Up @@ -77,18 +78,19 @@ const createComponents = async (uid, data) => {
throw new Error('Expected an array to create repeatable component');
}

componentBody[attributeName] = await Promise.all(
dynamiczoneValues.map(async (value) => {
const { id } = await createComponent(value.__component, value);
return {
id,
__component: value.__component,
__pivot: {
field: attributeName,
},
};
})
);
const dynamicZoneData = [];
for (const value of dynamiczoneValues) {
const { id } = await createComponent(value.__component, value);
dynamicZoneData.push({
id,
__component: value.__component,
__pivot: {
field: attributeName,
},
});
}

componentBody[attributeName] = dynamicZoneData;

continue;
}
Expand Down Expand Up @@ -137,9 +139,10 @@ const updateComponents = async (uid, entityToUpdate, data) => {
throw new Error('Expected an array to create repeatable component');
}

const components = await Promise.all(
componentValue.map((value) => updateOrCreateComponent(componentUID, value))
);
const components = [];
for (const value of componentValue) {
components.push(await updateOrCreateComponent(componentUID, value));
}

componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
return {
Expand Down Expand Up @@ -173,19 +176,19 @@ const updateComponents = async (uid, entityToUpdate, data) => {
throw new Error('Expected an array to create repeatable component');
}

componentBody[attributeName] = await Promise.all(
dynamiczoneValues.map(async (value) => {
const { id } = await updateOrCreateComponent(value.__component, value);
const dynamicZoneData = [];
for (const value of dynamiczoneValues) {
const { id } = await updateOrCreateComponent(value.__component, value);
dynamicZoneData.push({
id,
__component: value.__component,
__pivot: {
field: attributeName,
},
});
}

return {
id,
__component: value.__component,
__pivot: {
field: attributeName,
},
};
})
);
componentBody[attributeName] = dynamicZoneData;

continue;
}
Expand Down Expand Up @@ -287,14 +290,14 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =

if (attribute.type === 'component') {
const { component: componentUID } = attribute;
await Promise.all(
_.castArray(value).map((subValue) => deleteComponent(componentUID, subValue))
);
for (const subValue of _.castArray(value)) {
await deleteComponent(componentUID, subValue);
}
} else {
// delete dynamic zone components
await Promise.all(
_.castArray(value).map((subValue) => deleteComponent(subValue.__component, subValue))
);
for (const subValue of _.castArray(value)) {
await deleteComponent(subValue.__component, subValue);
}
}

continue;
Expand Down
1 change: 1 addition & 0 deletions packages/core/upload/server/services/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ module.exports = ({ strapi }) => ({
const formats = await generateResponsiveFormats(fileData);
if (Array.isArray(formats) && formats.length > 0) {
for (const format of formats) {
// eslint-disable-next-line no-continue
if (!format) continue;
uploadPromises.push(uploadResponsiveFormat(format));
}
Expand Down
8 changes: 6 additions & 2 deletions packages/plugins/i18n/server/services/localizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const syncLocalizations = async (entry, { model }) => {
return strapi.query(model.uid).update({ where: { id }, data: { localizations } });
};

await Promise.all(entry.localizations.map(({ id }) => updateLocalization(id)));
for (const localization of entry.localizations) {
await updateLocalization(localization.id);
}
}
};

Expand All @@ -56,7 +58,9 @@ const syncNonLocalizedAttributes = async (entry, { model }) => {
return strapi.entityService.update(model.uid, id, { data: nonLocalizedAttributes });
};

await Promise.all(entry.localizations.map(({ id }) => updateLocalization(id)));
for (const localization of entry.localizations) {
await updateLocalization(localization.id);
}
}
};

Expand Down

0 comments on commit c02061d

Please sign in to comment.