From f5896dbb8dbbf61d2bb57a6b058fb80d3be61a7b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 9 Aug 2014 18:01:28 -0400 Subject: [PATCH] Remove synchronous database methods This required doing additional caching at startup (e.g., item types and fields) so that various methods can remain synchronous. This lets us switch back to using the current Sqlite.jsm. Previously we were bundling the Fx24 version, which avoided freezes with locking_mode=EXCLUSIVE with both sync and async queries. Known broken things: - Autocomplete - Database backup - UDFs (e.g., REGEXP function used in Zotero.DB.getNextName()) --- chrome/content/zotero/advancedSearch.js | 20 +- chrome/content/zotero/browser.js | 16 +- .../preferences/preferences_advanced.js | 6 +- .../content/zotero/preferences/proxyEditor.js | 2 +- chrome/content/zotero/xpcom/attachments.js | 1 + .../content/zotero/xpcom/data/cachedTypes.js | 236 +++-- .../content/zotero/xpcom/data/dataObject.js | 2 +- .../content/zotero/xpcom/data/dataObjects.js | 35 +- chrome/content/zotero/xpcom/data/item.js | 4 +- .../content/zotero/xpcom/data/itemFields.js | 173 ++-- chrome/content/zotero/xpcom/data/libraries.js | 45 +- chrome/content/zotero/xpcom/data/relations.js | 8 +- chrome/content/zotero/xpcom/data/tags.js | 2 +- chrome/content/zotero/xpcom/db.js | 832 +++-------------- chrome/content/zotero/xpcom/error.js | 11 +- chrome/content/zotero/xpcom/fulltext.js | 2 +- chrome/content/zotero/xpcom/itemTreeView.js | 28 +- .../content/zotero/xpcom/mimeTypeHandler.js | 2 +- chrome/content/zotero/xpcom/proxy.js | 45 +- chrome/content/zotero/xpcom/schema.js | 234 +++-- chrome/content/zotero/xpcom/search.js | 38 +- chrome/content/zotero/xpcom/storage/zfs.js | 4 +- chrome/content/zotero/xpcom/sync.js | 5 +- chrome/content/zotero/xpcom/uri.js | 15 +- chrome/content/zotero/xpcom/zotero.js | 100 +- chrome/content/zotero/zoteroPane.js | 264 +++--- components/zotero-service.js | 1 + resource/Sqlite.jsm | 868 ------------------ resource/log4moz.js | 700 -------------- 29 files changed, 733 insertions(+), 2966 deletions(-) delete mode 100644 resource/Sqlite.jsm delete mode 100644 resource/log4moz.js diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js index 7550f9e745..e614f771ab 100644 --- a/chrome/content/zotero/advancedSearch.js +++ b/chrome/content/zotero/advancedSearch.js @@ -28,7 +28,6 @@ var ZoteroAdvancedSearch = new function() { this.onLoad = onLoad; this.search = search; this.clear = clear; - this.save = save; this.onDblClick = onDblClick; this.onUnload = onUnload; @@ -104,13 +103,13 @@ var ZoteroAdvancedSearch = new function() { } - function save() { + this.save = Zotero.Promise.coroutine(function* () { _searchBox.updateSearch(); var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); - var untitled = Zotero.DB.getNextName( + var untitled = yield Zotero.DB.getNextName( _searchBox.search.libraryID, 'savedSearches', 'savedSearchName', @@ -132,15 +131,12 @@ var ZoteroAdvancedSearch = new function() { name.value = untitled; } - return _searchBox.search.clone() - .then(function (s) { - s.name = name.value; - return s.save(); - }) - .then(function () { - window.close() - }); - } + var s = yield _searchBox.search.clone(); + s.name = name.value; + yield s.save(); + + window.close() + }); this.onLibraryChange = function (libraryID) { diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index e96f82ead5..230c6a1af1 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -159,7 +159,7 @@ var Zotero_Browser = new function() { var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); if(tab.page.translators && tab.page.translators.length) { tab.page.translate.setTranslator(translator || tab.page.translators[0]); - Zotero_Browser.performTranslation(tab.page.translate); + Zotero_Browser.performTranslation(tab.page.translate); // TODO: async } } @@ -493,7 +493,7 @@ var Zotero_Browser = new function() { * have been called * @param {Zotero.Translate} translate */ - this.performTranslation = function(translate, libraryID, collection) { + this.performTranslation = Zotero.Promise.coroutine(function* (translate, libraryID, collection) { if (Zotero.locked) { Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); var desc = Zotero.localeJoin([ @@ -506,15 +506,7 @@ var Zotero_Browser = new function() { return; } - if (!Zotero.stateCheck()) { - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); - var desc = Zotero.getString("ingester.scrapeErrorDescription.previousError") - + ' ' + Zotero.getString("general.restartFirefoxAndTryAgain", Zotero.appName); - Zotero_Browser.progress.addDescription(desc); - Zotero_Browser.progress.show(); - Zotero_Browser.progress.startCloseTimer(8000); - return; - } + yield Zotero.DB.waitForTransaction(); Zotero_Browser.progress.show(); Zotero_Browser.isScraping = true; @@ -615,7 +607,7 @@ var Zotero_Browser = new function() { }); translate.translate(libraryID); - } + }); ////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js index f7b7c949e4..492f6d2f7f 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.js +++ b/chrome/content/zotero/preferences/preferences_advanced.js @@ -47,11 +47,11 @@ Zotero_Preferences.Advanced = { }, - runIntegrityCheck: function () { + runIntegrityCheck: Zotero.Promise.coroutine(function* () { var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); - var ok = Zotero.DB.integrityCheck(); + var ok = yield Zotero.DB.integrityCheck(); if (ok) { ok = Zotero.Schema.integrityCheck(); if (!ok) { @@ -110,7 +110,7 @@ Zotero_Preferences.Advanced = { Zotero.getString('general.' + str), Zotero.getString('db.integrityCheck.' + str) + (!ok ? "\n\n" + Zotero.getString('db.integrityCheck.dbRepairTool') : '')); - }, + }), resetTranslatorsAndStyles: function () { diff --git a/chrome/content/zotero/preferences/proxyEditor.js b/chrome/content/zotero/preferences/proxyEditor.js index 542ee3b402..98347728a6 100644 --- a/chrome/content/zotero/preferences/proxyEditor.js +++ b/chrome/content/zotero/preferences/proxyEditor.js @@ -122,7 +122,7 @@ var Zotero_ProxyEditor = new function() { window, Zotero.getString("proxies.error"), Zotero.getString("proxies.error." + error, hasErrors) ); - if(window.arguments && window.arguments[0]) proxy.revert(); + if(window.arguments && window.arguments[0]) proxy.revert(); // async return false; } proxy.save(true); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index e6339b090d..4884b93773 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -82,6 +82,7 @@ Zotero.Attachments = new function(){ yield _postProcessFile(itemID, newFile, contentType); }.bind(this)) .catch(function (e) { + Zotero.debug(e, 1); var msg = "Failed importing file " + file.path; Components.utils.reportError(msg); Zotero.debug(msg, 1); diff --git a/chrome/content/zotero/xpcom/data/cachedTypes.js b/chrome/content/zotero/xpcom/data/cachedTypes.js index 82864be9b4..1cf5c2fb44 100644 --- a/chrome/content/zotero/xpcom/data/cachedTypes.js +++ b/chrome/content/zotero/xpcom/data/cachedTypes.js @@ -43,8 +43,8 @@ * */ Zotero.CachedTypes = function() { - var _types = []; - var _typesLoaded; + this._types = null; + this._typesArray = null; var self = this; // Override these variables in child classes @@ -57,11 +57,38 @@ Zotero.CachedTypes = function() { this.getName = getName; this.getID = getID; - this.getTypes = getTypes; + + + this.init = Zotero.Promise.coroutine(function* () { + this._types = {}; + this._typesArray = []; + + var types = yield this._getTypesFromDB(); + for (let i=0; i