Use rowid to clean invalid entries from translatorCache

Since in truly weird cases [1] fileName might not exist

https://forums.zotero.org/discussion/comment/300558/#Comment_300558
This commit is contained in:
Dan Stillman 2018-02-06 23:45:13 -05:00
parent 46854b6b23
commit 06fb74aafd
2 changed files with 7 additions and 6 deletions

View file

@ -744,7 +744,7 @@ Zotero.Schema = new function(){
index[id].extract = true; index[id].extract = true;
} }
let sql = "SELECT fileName, metadataJSON FROM translatorCache"; let sql = "SELECT rowid, fileName, metadataJSON FROM translatorCache";
let rows = yield Zotero.DB.queryAsync(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
for (let i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
@ -757,10 +757,10 @@ Zotero.Schema = new function(){
Zotero.logError(e); Zotero.logError(e);
Zotero.debug(json, 1); Zotero.debug(json, 1);
// // If JSON is invalid, clear from cache // If JSON is invalid, clear from cache
yield Zotero.DB.queryAsync( yield Zotero.DB.queryAsync(
"DELETE FROM translatorCache WHERE fileName=?", "DELETE FROM translatorCache WHERE rowid=?",
rows[i].fileName rows[i].rowid
); );
continue; continue;
} }

View file

@ -68,7 +68,7 @@ Zotero.Translators = new function() {
_cache = {"import":[], "export":[], "web":[], "webWithTargetAll":[], "search":[]}; _cache = {"import":[], "export":[], "web":[], "webWithTargetAll":[], "search":[]};
_translators = {}; _translators = {};
var sql = "SELECT fileName, metadataJSON, lastModifiedTime FROM translatorCache"; var sql = "SELECT rowid, fileName, metadataJSON, lastModifiedTime FROM translatorCache";
var dbCacheResults = yield Zotero.DB.queryAsync(sql); var dbCacheResults = yield Zotero.DB.queryAsync(sql);
var dbCache = {}; var dbCache = {};
for (let i = 0; i < dbCacheResults.length; i++) { for (let i = 0; i < dbCacheResults.length; i++) {
@ -211,7 +211,8 @@ Zotero.Translators = new function() {
for (let fileName in dbCache) { for (let fileName in dbCache) {
if (!filesInCache[fileName]) { if (!filesInCache[fileName]) {
yield Zotero.DB.queryAsync( yield Zotero.DB.queryAsync(
"DELETE FROM translatorCache WHERE fileName = ?", fileName "DELETE FROM translatorCache WHERE rowid=?",
dbCache[fileName].rowid
); );
} }
} }