mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-03-13 18:22:14 -07:00
Unconditionally decrement transaction depth (#8008)
…otherwise we may end up in a situation where we're always stuck in an "already in a transaction" state and often neglect to actually enter a real transaction!
This commit is contained in:
parent
d7d0733177
commit
de4fe132a7
1 changed files with 15 additions and 13 deletions
|
|
@ -507,20 +507,22 @@ TODO: better-sqlite3 provides its own transaction method which we should be usin
|
|||
SqlTiddlerDatabase.prototype.transaction = function(fn) {
|
||||
const alreadyInTransaction = this.transactionDepth > 0;
|
||||
this.transactionDepth++;
|
||||
if(alreadyInTransaction) {
|
||||
return fn();
|
||||
} else {
|
||||
this.runStatement(`BEGIN TRANSACTION`);
|
||||
try {
|
||||
var result = fn();
|
||||
this.runStatement(`COMMIT TRANSACTION`);
|
||||
} catch(e) {
|
||||
this.runStatement(`ROLLBACK TRANSACTION`);
|
||||
throw(e);
|
||||
} finally {
|
||||
this.transactionDepth--;
|
||||
try {
|
||||
if(alreadyInTransaction) {
|
||||
return fn();
|
||||
} else {
|
||||
this.runStatement(`BEGIN TRANSACTION`);
|
||||
try {
|
||||
var result = fn();
|
||||
this.runStatement(`COMMIT TRANSACTION`);
|
||||
} catch(e) {
|
||||
this.runStatement(`ROLLBACK TRANSACTION`);
|
||||
throw(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
this.transactionDepth--;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue