Fix translator architecture hangs on bad JSON in translatorCache
This commit is contained in:
parent
2b8311d3d7
commit
cc9efde843
|
@ -744,16 +744,29 @@ Zotero.Schema = new function(){
|
||||||
index[id].extract = true;
|
index[id].extract = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sql = "SELECT metadataJSON FROM translatorCache";
|
let sql = "SELECT fileName, metadataJSON FROM translatorCache";
|
||||||
let dbCache = yield Zotero.DB.columnQueryAsync(sql);
|
let rows = yield Zotero.DB.queryAsync(sql);
|
||||||
// If there's anything in the cache, see what we actually need to extract
|
// If there's anything in the cache, see what we actually need to extract
|
||||||
if (dbCache) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
for (let i = 0; i < dbCache.length; i++) {
|
let json = rows[i].metadataJSON;
|
||||||
let metadata = JSON.parse(dbCache[i]);
|
let metadata;
|
||||||
let id = metadata.translatorID;
|
try {
|
||||||
if (index[id] && index[id].lastUpdated <= metadata.lastUpdated) {
|
metadata = JSON.parse(json);
|
||||||
index[id].extract = false;
|
}
|
||||||
}
|
catch (e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
Zotero.debug(json, 1);
|
||||||
|
|
||||||
|
// // If JSON is invalid, clear from cache
|
||||||
|
yield Zotero.DB.queryAsync(
|
||||||
|
"DELETE FROM translatorCache WHERE fileName=?",
|
||||||
|
rows[i].fileName
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let id = metadata.translatorID;
|
||||||
|
if (index[id] && index[id].lastUpdated <= metadata.lastUpdated) {
|
||||||
|
index[id].extract = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,22 @@ Zotero.Translators = new function() {
|
||||||
|
|
||||||
// Get JSON from cache if possible
|
// Get JSON from cache if possible
|
||||||
if (memCacheJSON || dbCacheEntry) {
|
if (memCacheJSON || dbCacheEntry) {
|
||||||
var translator = Zotero.Translators.load(
|
try {
|
||||||
memCacheJSON || dbCacheEntry.metadataJSON, path
|
var translator = Zotero.Translators.load(
|
||||||
);
|
memCacheJSON || dbCacheEntry.metadataJSON, path
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
Zotero.debug(memCacheJSON || dbCacheEntry.metadataJSON, 1);
|
||||||
|
|
||||||
|
// If JSON is invalid, clear from cache
|
||||||
|
yield Zotero.DB.queryAsync(
|
||||||
|
"DELETE FROM translatorCache WHERE fileName=?",
|
||||||
|
fileName
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, load from file
|
// Otherwise, load from file
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user