Use lastUpdated dates to determine whether to update translators

This commit is contained in:
Simon Kornblith 2011-06-30 06:36:48 +00:00
parent b1584a1eae
commit aeef8ecc15
3 changed files with 17 additions and 18 deletions

View file

@ -41,18 +41,10 @@ Zotero.Repo = new function() {
_updateFromStandalone(_nextCheck <= Date.now());
};
/**
* Reset all translators and code
*/
this.reset = function(callback) {
Zotero.Prefs.set("connector.repo.lastCheck.repoTime", 0);
this.update(true);
};
/**
* Force updating translators
*/
var update = this.update = function(reset, callback) {
var update = this.update = function(reset) {
_updateFromStandalone(true, reset);
};
@ -121,7 +113,7 @@ Zotero.Repo = new function() {
*/
function _updateFromRepo(reset, callback) {
var url = ZOTERO_CONFIG.REPOSITORY_URL+"/metadata?last="+
Zotero.Prefs.get("connector.repo.lastCheck.repoTime");
(reset ? "0" : Zotero.Prefs.get("connector.repo.lastCheck.repoTime"));
Zotero.HTTP.doGet(url, function(xmlhttp) {
var success = xmlhttp.status === 200;

View file

@ -244,9 +244,19 @@ Zotero.Translators = new function() {
var newTranslator = new Zotero.Translator(newMetadata[i]);
if(_translators.hasOwnProperty(newTranslator.translatorID)) {
if(_translators[newTranslator.translatorID].lastUpdated !== newTranslator.lastUpdated) {
var oldLastUpdated = _translators[newTranslator.translatorID].lastUpdated;
// check whether translator has changed
if(oldLastUpdated !== newTranslator.lastUpdated) {
// check whether newTranslator is actually newer than the existing
// translator, and if not, don't update
if(Zotero.Date.sqlToDate(newTranslator.lastUpdated) < Zotero.Date.sqlToDate(oldLastUpdated)) {
Zotero.debug("Translators: Received older version of "+newTranslator.label+" from repo ("+newTranslator.lastUpdated+" vs. "+oldLastUpdated+")");
continue;
}
if(!Zotero.isFx) {
// if lastUpdated does not match between old and new translator
// if lastUpdated does not match between old and new translator,
// invalidate translator code cache
delete localStorage["translatorCode-"+newTranslator.translatorID];
}
@ -336,7 +346,7 @@ Zotero.Translators.CodeGetter.prototype.getCodeFor = function(i) {
}
const TRANSLATOR_REQUIRED_PROPERTIES = ["translatorID", "translatorType", "label", "creator", "target",
"priority"];
"priority", "lastUpdated"];
var TRANSLATOR_PASSING_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES.concat(["displayOptions", "configOptions",
"browserSupport", "code", "runMode"]);
var TRANSLATOR_SAVE_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES.concat(["browserSupport"]);

View file

@ -215,17 +215,14 @@ Zotero.Server.Connector.GetTranslators.prototype = {
// Translator data
var responseData = [];
// TODO only send necessary translators
var translators = Zotero.Translators.getAll();
for each(var translator in translators) {
let serializableTranslator = {};
for each(var key in ["translatorID", "translatorType", "label", "creator", "target",
"priority", "browserSupport"]) {
"minVersion", "maxVersion", "configOptions", "displayOptions", "priority",
"browserSupport", "inRepository", "lastUpdated"]) {
serializableTranslator[key] = translator[key];
}
// Do not pass targetless translators that do not support this browser (since that
// would mean passing each page back to Zotero)
responseData.push(serializableTranslator);
}