From af7da366c9478c0f63b04dd9d20a21ff2a75b859 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 10 May 2015 02:54:38 -0400 Subject: [PATCH] Get connection without yielding if available in executeTransaction --- chrome/content/zotero/xpcom/db.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index e9d70166a..ee7be6def 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -501,7 +501,7 @@ Zotero.DBConnection.prototype.executeTransaction = Zotero.Promise.coroutine(func this._callbacks.begin[i](); } } - var conn = yield this._getConnectionAsync(options); + var conn = this._getConnection(options) || (yield this._getConnectionAsync(options)); var result = yield conn.executeTransaction(func); Zotero.debug("Committed async DB transaction", 5); this._inTransaction = false; @@ -1111,6 +1111,16 @@ Zotero.DBConnection.prototype.getSQLDataType = function(value) { // ///////////////////////////////////////////////////////////////// +Zotero.DBConnection.prototype._getConnection = function (options) { + if (this._backupPromise && this._backupPromise.isPending() && (!options || !options.inBackup)) { + return false; + } + if (this._connectionAsync === false) { + throw new Error("Database permanently closed; not re-opening"); + } + return this._connectionAsync || false; +} + /* * Retrieve a link to the data store asynchronously */