commit 04516af552f47633482c060097077f7b179a2d4e
parent 98720462feff0dc3df5b457d908e232de67241ac
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 8 Dec 2016 19:17:49 -0500
Stop using Zotero.lazy() for Zotero.Translators.init()
It makes things too complicated with some of the logic necessary for bundled
file updating.
Diffstat:
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -464,22 +464,22 @@ Zotero.Schema = new function(){
}
installLocation = installLocation.path;
- let reinitOptions = { fromSchemaUpdate: true, noReinit: true };
+ let initOpts = { fromSchemaUpdate: true };
// Update files
switch (mode) {
case 'styles':
- yield Zotero.Styles.reinit(reinitOptions);
+ yield Zotero.Styles.init(initOpts);
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
case 'translators':
- yield Zotero.Translators.reinit(reinitOptions);
+ yield Zotero.Translators.init(initOpts);
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
default:
- yield Zotero.Translators.reinit(reinitOptions);
+ yield Zotero.Translators.init(initOpts);
let up1 = yield _updateBundledFilesAtLocation(installLocation, 'translators', true);
- yield Zotero.Styles.reinit(reinitOptions);
+ yield Zotero.Styles.init(initOpts);
let up2 = yield _updateBundledFilesAtLocation(installLocation, 'styles');
var updated = up1 || up2;
}
diff --git a/chrome/content/zotero/xpcom/translation/translators.js b/chrome/content/zotero/xpcom/translation/translators.js
@@ -35,6 +35,7 @@ var TRANSLATOR_TYPES = {"import":1, "export":2, "web":4, "search":8};
Zotero.Translators = new function() {
var _cache, _translators;
var _initialized = false;
+ var _initializationDeferred = false;
/**
* Initializes translator cache, loading all translator metadata into memory
@@ -42,18 +43,17 @@ Zotero.Translators = new function() {
* @param {Object} [options.metadataCache] - Translator metadata keyed by filename, if already
* available (e.g., in updateBundledFiles()), to avoid unnecesary file reads
*/
- this.reinit = Zotero.Promise.coroutine(function* (options = {}) {
+ this.init = Zotero.Promise.coroutine(function* (options = {}) {
+ if (_initializationDeferred && !options.reinit) {
+ return _initializationDeferred.promise;
+ }
+ _initializationDeferred = Zotero.Promise.defer();
+
// Wait until bundled files have been updated, except when this is called by the schema update
// code itself
if (!options.fromSchemaUpdate) {
yield Zotero.Schema.schemaUpdatePromise;
}
- // Before bundled files can be updated, any existing translators need to be loaded, but other
- // init() calls from elsewhere should still wait on schemaUpdatePromise, so init()/lazy()
- // can't be used. Instead, the schema update code calls reinit() with noReinit.
- else if (options.noReinit && _initialized) {
- return;
- }
Zotero.debug("Initializing translators");
var start = new Date;
@@ -211,12 +211,18 @@ Zotero.Translators = new function() {
_cache[type].sort(cmp);
}
+ _initializationDeferred.resolve();
_initialized = true;
Zotero.debug("Cached " + numCached + " translators in " + ((new Date) - start) + " ms");
});
- this.init = Zotero.lazy(this.reinit);
-
+
+
+ this.reinit = function (options = {}) {
+ return this.init(Object.assign({}, options, { reinit: true }));
+ };
+
+
/**
* Loads a translator from JSON, with optional code
*