Stop using Zotero.lazy() for Zotero.Translators.init()
It makes things too complicated with some of the logic necessary for bundled file updating.
This commit is contained in:
parent
98720462fe
commit
04516af552
|
@ -464,22 +464,22 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
installLocation = installLocation.path;
|
installLocation = installLocation.path;
|
||||||
|
|
||||||
let reinitOptions = { fromSchemaUpdate: true, noReinit: true };
|
let initOpts = { fromSchemaUpdate: true };
|
||||||
|
|
||||||
// Update files
|
// Update files
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'styles':
|
case 'styles':
|
||||||
yield Zotero.Styles.reinit(reinitOptions);
|
yield Zotero.Styles.init(initOpts);
|
||||||
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
|
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
|
||||||
|
|
||||||
case 'translators':
|
case 'translators':
|
||||||
yield Zotero.Translators.reinit(reinitOptions);
|
yield Zotero.Translators.init(initOpts);
|
||||||
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
|
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
yield Zotero.Translators.reinit(reinitOptions);
|
yield Zotero.Translators.init(initOpts);
|
||||||
let up1 = yield _updateBundledFilesAtLocation(installLocation, 'translators', true);
|
let up1 = yield _updateBundledFilesAtLocation(installLocation, 'translators', true);
|
||||||
yield Zotero.Styles.reinit(reinitOptions);
|
yield Zotero.Styles.init(initOpts);
|
||||||
let up2 = yield _updateBundledFilesAtLocation(installLocation, 'styles');
|
let up2 = yield _updateBundledFilesAtLocation(installLocation, 'styles');
|
||||||
var updated = up1 || up2;
|
var updated = up1 || up2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ var TRANSLATOR_TYPES = {"import":1, "export":2, "web":4, "search":8};
|
||||||
Zotero.Translators = new function() {
|
Zotero.Translators = new function() {
|
||||||
var _cache, _translators;
|
var _cache, _translators;
|
||||||
var _initialized = false;
|
var _initialized = false;
|
||||||
|
var _initializationDeferred = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes translator cache, loading all translator metadata into memory
|
* 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
|
* @param {Object} [options.metadataCache] - Translator metadata keyed by filename, if already
|
||||||
* available (e.g., in updateBundledFiles()), to avoid unnecesary file reads
|
* 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
|
// Wait until bundled files have been updated, except when this is called by the schema update
|
||||||
// code itself
|
// code itself
|
||||||
if (!options.fromSchemaUpdate) {
|
if (!options.fromSchemaUpdate) {
|
||||||
yield Zotero.Schema.schemaUpdatePromise;
|
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");
|
Zotero.debug("Initializing translators");
|
||||||
var start = new Date;
|
var start = new Date;
|
||||||
|
@ -211,11 +211,17 @@ Zotero.Translators = new function() {
|
||||||
_cache[type].sort(cmp);
|
_cache[type].sort(cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_initializationDeferred.resolve();
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
|
|
||||||
Zotero.debug("Cached " + numCached + " translators in " + ((new Date) - start) + " ms");
|
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
|
* Loads a translator from JSON, with optional code
|
||||||
|
|
Loading…
Reference in New Issue
Block a user