Fix connector translator caching from repo and standalone
This commit is contained in:
parent
2f65c7d29c
commit
8e083c688a
2 changed files with 12 additions and 10 deletions
|
@ -150,7 +150,8 @@ Zotero.Repo = new function() {
|
||||||
if(!result && tryRepoOnFailure) {
|
if(!result && tryRepoOnFailure) {
|
||||||
_updateFromRepo(reset, callback);
|
_updateFromRepo(reset, callback);
|
||||||
} else {
|
} else {
|
||||||
_handleResponse(result, reset);
|
// Standalone always returns all translators without .deleted property
|
||||||
|
_handleResponse(result, true);
|
||||||
if(callback) callback(!!result);
|
if(callback) callback(!!result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -222,18 +222,19 @@ Zotero.Translators = new function() {
|
||||||
* the specified translators.
|
* the specified translators.
|
||||||
*/
|
*/
|
||||||
this.update = function(newMetadata, reset) {
|
this.update = function(newMetadata, reset) {
|
||||||
if(!_initialized) Zotero.Translators.init();
|
if (!_initialized) Zotero.Translators.init();
|
||||||
if(!newMetadata.length) return;
|
if (!newMetadata.length) return;
|
||||||
|
var serializedTranslators = [];
|
||||||
|
|
||||||
if(!reset) {
|
if (reset) {
|
||||||
var existingTranslatorIDs = new Set();
|
serializedTranslators = newMetadata.map((t) => new Zotero.Translator(t));
|
||||||
var serializedTranslators = [];
|
}
|
||||||
|
else {
|
||||||
var hasChanged = false;
|
var hasChanged = false;
|
||||||
|
|
||||||
// Update translators with new metadata
|
// Update translators with new metadata
|
||||||
for(var i in newMetadata) {
|
for(var i in newMetadata) {
|
||||||
var newTranslator = newMetadata[i];
|
var newTranslator = newMetadata[i];
|
||||||
existingTranslatorIDs.add(newTranslator.translatorID);
|
|
||||||
|
|
||||||
if(_translators.hasOwnProperty(newTranslator.translatorID)) {
|
if(_translators.hasOwnProperty(newTranslator.translatorID)) {
|
||||||
var oldTranslator = _translators[newTranslator.translatorID];
|
var oldTranslator = _translators[newTranslator.translatorID];
|
||||||
|
@ -257,11 +258,11 @@ Zotero.Translators = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let deletedTranslators = Object.keys(_translators).filter(id => !existingTranslatorIDs.has(id));
|
let deletedTranslators = Object.keys(_translators).filter(id => _translators[id].deleted);
|
||||||
if (deletedTranslators.length) {
|
if (deletedTranslators.length) {
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
for (let id of deletedTranslators) {
|
for (let id of deletedTranslators) {
|
||||||
Zotero.debug(`Translators: Removing ${_translators[ID].label}`);
|
Zotero.debug(`Translators: Removing ${_translators[id].label}`);
|
||||||
delete _translators[id];
|
delete _translators[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,7 +327,7 @@ Zotero.Translators.CodeGetter.prototype.getCodeFor = Zotero.Promise.method(funct
|
||||||
// include test cases)
|
// include test cases)
|
||||||
|| (Zotero.Repo && translator.codeSource === Zotero.Repo.SOURCE_REPO)))) {
|
|| (Zotero.Repo && translator.codeSource === Zotero.Repo.SOURCE_REPO)))) {
|
||||||
// get code
|
// get code
|
||||||
return translator.getCode();
|
return translator.getCode().catch((e) => Zotero.debug(`Failed to retrieve code for ${translator.translatorID}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue