mirror of
https://github.com/strapi/strapi.git
synced 2026-01-06 12:13:52 +00:00
Merge pull request #16364 from strapi/fix/mysql-deadlock-performance-issues
This commit is contained in:
commit
e71fa3ec1e
@ -51,6 +51,10 @@ class Database {
|
||||
return this.entityManager.getRepository(uid);
|
||||
}
|
||||
|
||||
inTransaction() {
|
||||
return !!transactionCtx.get();
|
||||
}
|
||||
|
||||
async transaction(cb) {
|
||||
const notNestedTransaction = !transactionCtx.get();
|
||||
const trx = notNestedTransaction ? await this.connection.transaction() : transactionCtx.get();
|
||||
|
||||
@ -49,7 +49,7 @@ const createComponents = async (uid, data) => {
|
||||
const components = await mapAsync(
|
||||
componentValue,
|
||||
(value) => createComponent(componentUID, value),
|
||||
{ concurrency: isDialectMySQL() ? 1 : Infinity }
|
||||
{ concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity }
|
||||
);
|
||||
|
||||
componentBody[attributeName] = components.map(({ id }) => {
|
||||
@ -97,7 +97,7 @@ const createComponents = async (uid, data) => {
|
||||
componentBody[attributeName] = await mapAsync(
|
||||
dynamiczoneValues,
|
||||
createDynamicZoneComponents,
|
||||
{ concurrency: isDialectMySQL() ? 1 : Infinity }
|
||||
{ concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity }
|
||||
);
|
||||
|
||||
continue;
|
||||
@ -151,7 +151,7 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
||||
const components = await mapAsync(
|
||||
componentValue,
|
||||
(value) => updateOrCreateComponent(componentUID, value),
|
||||
{ concurrency: isDialectMySQL() ? 1 : Infinity }
|
||||
{ concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity }
|
||||
);
|
||||
|
||||
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
|
||||
@ -200,7 +200,7 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
||||
},
|
||||
};
|
||||
},
|
||||
{ concurrency: isDialectMySQL() ? 1 : Infinity }
|
||||
{ concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity }
|
||||
);
|
||||
|
||||
continue;
|
||||
@ -305,7 +305,7 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
||||
const { component: componentUID } = attribute;
|
||||
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
|
||||
await mapAsync(_.castArray(value), (subValue) => deleteComponent(componentUID, subValue), {
|
||||
concurrency: isDialectMySQL() ? 1 : Infinity,
|
||||
concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity,
|
||||
});
|
||||
} else {
|
||||
// delete dynamic zone components
|
||||
@ -313,7 +313,7 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
||||
await mapAsync(
|
||||
_.castArray(value),
|
||||
(subValue) => deleteComponent(subValue.__component, subValue),
|
||||
{ concurrency: isDialectMySQL() ? 1 : Infinity }
|
||||
{ concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -41,8 +41,9 @@ const syncLocalizations = async (entry, { model }) => {
|
||||
};
|
||||
|
||||
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
|
||||
// TODO: use a transaction to avoid deadlocks
|
||||
await mapAsync(entry.localizations, (localization) => updateLocalization(localization.id), {
|
||||
concurrency: isDialectMySQL() ? 1 : Infinity,
|
||||
concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity,
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -68,8 +69,9 @@ const syncNonLocalizedAttributes = async (entry, { model }) => {
|
||||
};
|
||||
|
||||
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
|
||||
// TODO: use a transaction to avoid deadlocks
|
||||
await mapAsync(entry.localizations, (localization) => updateLocalization(localization.id), {
|
||||
concurrency: isDialectMySQL() ? 1 : Infinity,
|
||||
concurrency: isDialectMySQL() && !strapi.db.inTransaction() ? 1 : Infinity,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user