Don't reindex downloaded full-text content if already up to date
This commit is contained in:
parent
6e9b491e82
commit
342e631beb
1 changed files with 39 additions and 16 deletions
|
@ -724,41 +724,64 @@ Zotero.Fulltext = new function(){
|
||||||
* Save full-text content and stats to a cache file
|
* Save full-text content and stats to a cache file
|
||||||
*/
|
*/
|
||||||
this.setItemContent = function (libraryID, key, text, stats, version) {
|
this.setItemContent = function (libraryID, key, text, stats, version) {
|
||||||
|
var libraryKey = libraryID + "/" + key;
|
||||||
var item = Zotero.Items.getByLibraryAndKey(libraryID, key);
|
var item = Zotero.Items.getByLibraryAndKey(libraryID, key);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
let msg = "Item not found setting full-text content";
|
let msg = "Item " + libraryKey + " not found setting full-text content";
|
||||||
Zotero.debug(msg, 1);
|
Zotero.debug(msg, 1);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var itemID = item.id;
|
var itemID = item.id;
|
||||||
|
|
||||||
|
var currentVersion = Zotero.DB.valueQuery(
|
||||||
|
"SELECT version FROM fulltextItems WHERE itemID=?", itemID
|
||||||
|
);
|
||||||
|
|
||||||
if (text !== '') {
|
if (text !== '') {
|
||||||
var cacheFile = this.getItemProcessorCacheFile(itemID);
|
var processorCacheFile = this.getItemProcessorCacheFile(itemID);
|
||||||
|
var itemCacheFile = this.getItemCacheFile(itemID);
|
||||||
|
|
||||||
// If a storage directory doesn't exist, create it
|
// If a storage directory doesn't exist, create it
|
||||||
if (!cacheFile.parent.exists()) {
|
if (!processorCacheFile.parent.exists()) {
|
||||||
Zotero.Attachments.createDirectoryForItem(itemID);
|
Zotero.Attachments.createDirectoryForItem(itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug("Writing full-text content and data to " + cacheFile.path);
|
// If the local version of the content is already up to date and cached, skip
|
||||||
Zotero.File.putContents(cacheFile, JSON.stringify({
|
if (currentVersion && currentVersion == version && itemCacheFile.exists()) {
|
||||||
indexedChars: stats.indexedChars,
|
Zotero.debug("Current full-text content version matches remote for item "
|
||||||
totalChars: stats.totalChars,
|
+ libraryKey + " -- skipping");
|
||||||
indexedPages: stats.indexedPages,
|
var synced = SYNC_STATE_IN_SYNC;
|
||||||
totalPages: stats.totalPages,
|
}
|
||||||
version: version,
|
// If the local version is 0 but the text matches, just update the version
|
||||||
text: text
|
else if (currentVersion == 0 && itemCacheFile.exists()
|
||||||
}));
|
&& Zotero.File.getContents(itemCacheFile) == text) {
|
||||||
var synced = SYNC_STATE_TO_PROCESS;
|
Zotero.debug("Current full-text content matches remote for item "
|
||||||
|
+ libraryKey + " -- updating version");
|
||||||
|
var synced = SYNC_STATE_IN_SYNC;
|
||||||
|
Zotero.DB.query("UPDATE fulltextItems SET version=? WHERE itemID=?", [version, itemID]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Zotero.debug("Writing full-text content and data for item " + libraryKey
|
||||||
|
+ " to " + processorCacheFile.path);
|
||||||
|
Zotero.File.putContents(processorCacheFile, JSON.stringify({
|
||||||
|
indexedChars: stats.indexedChars,
|
||||||
|
totalChars: stats.totalChars,
|
||||||
|
indexedPages: stats.indexedPages,
|
||||||
|
totalPages: stats.totalPages,
|
||||||
|
version: version,
|
||||||
|
text: text
|
||||||
|
}));
|
||||||
|
var synced = SYNC_STATE_TO_PROCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Zotero.debug("Marking full-text content for download");
|
Zotero.debug("Marking full-text content for download for item " + libraryKey);
|
||||||
var synced = SYNC_STATE_TO_DOWNLOAD;
|
var synced = SYNC_STATE_TO_DOWNLOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the item as unprocessed
|
// If indexed previously, update the sync state
|
||||||
if (Zotero.DB.valueQuery("SELECT COUNT(*) FROM fulltextItems WHERE itemID=?", itemID)) {
|
if (currentVersion !== false) {
|
||||||
Zotero.DB.query("UPDATE fulltextItems SET synced=? WHERE itemID=?", [synced, itemID]);
|
Zotero.DB.query("UPDATE fulltextItems SET synced=? WHERE itemID=?", [synced, itemID]);
|
||||||
}
|
}
|
||||||
// If not yet indexed, add an empty row
|
// If not yet indexed, add an empty row
|
||||||
|
|
Loading…
Add table
Reference in a new issue