From de4fe132a78c19e9c4d26a3289a1484435c9fe2d Mon Sep 17 00:00:00 2001 From: Rob Hoelz Date: Mon, 26 Feb 2024 05:02:55 -0600 Subject: [PATCH] Unconditionally decrement transaction depth (#8008) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …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! --- .../modules/sql-tiddler-database.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js index 959642378..d528021a5 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js @@ -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--; } };