mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Wrapped data generator data creation in transaction function
ref PROD-233 Errors were not handled properly because of a missing rollback and try/catch. Using a function is easier generally. Also added ignored contraint checks to increase performance a tiny bit. They ended up not mattering much, so we can consider to remove them again.
This commit is contained in:
parent
eebf0e2eaf
commit
52566dc1e0
@ -149,7 +149,10 @@ class DataGenerator {
|
||||
}
|
||||
|
||||
async importData() {
|
||||
const transaction = await this.knex.transaction();
|
||||
await this.knex.transaction(async (transaction) => {
|
||||
// Performance improvements
|
||||
await this.knex.raw('SET FOREIGN_KEY_CHECKS=0;').transacting(transaction);
|
||||
await this.knex.raw('SET unique_checks=0;').transacting(transaction);
|
||||
|
||||
// Add default tables if none are specified
|
||||
if (this.tableList.length === 0) {
|
||||
@ -243,7 +246,10 @@ class DataGenerator {
|
||||
await tableImporter.finalise();
|
||||
}
|
||||
|
||||
await transaction.commit();
|
||||
// Performance improvements
|
||||
await this.knex.raw('SET FOREIGN_KEY_CHECKS=1;').transacting(transaction);
|
||||
await this.knex.raw('SET unique_checks=1;').transacting(transaction);
|
||||
}, {isolationLevel: 'read committed'});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user