Upload objects earlier than earliest object mod time on server -- with any luck, this will fix the majority of "Invalid response" sync errors
This commit is contained in:
parent
11f2810586
commit
79a89184d2
7 changed files with 81 additions and 63 deletions
|
@ -30,7 +30,6 @@ Zotero.Collections = new function() {
|
|||
|
||||
this.get = get;
|
||||
this.add = add;
|
||||
this.getUpdated = getUpdated;
|
||||
this.getCollectionsContainingItems = getCollectionsContainingItems;
|
||||
this.erase = erase;
|
||||
|
||||
|
@ -62,16 +61,6 @@ Zotero.Collections = new function() {
|
|||
}
|
||||
|
||||
|
||||
function getUpdated(date) {
|
||||
var sql = "SELECT collectionID FROM collections";
|
||||
if (date) {
|
||||
sql += " WHERE dateModified>?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return Zotero.DB.columnQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
function getCollectionsContainingItems(itemIDs, asIDs) {
|
||||
var sql = "SELECT collectionID FROM collections WHERE ";
|
||||
var sqlParams = [];
|
||||
|
|
|
@ -26,7 +26,6 @@ Zotero.Creators = new function() {
|
|||
this.constructor.prototype = new Zotero.DataObjects();
|
||||
|
||||
this.get = get;
|
||||
this.getUpdated = getUpdated;
|
||||
this.getDataID = getDataID;
|
||||
this.getCreatorsWithData = getCreatorsWithData;
|
||||
this.countCreatorsWithData = countCreatorsWithData;
|
||||
|
@ -59,16 +58,6 @@ Zotero.Creators = new function() {
|
|||
}
|
||||
|
||||
|
||||
function getUpdated(date) {
|
||||
var sql = "SELECT creatorID FROM creators";
|
||||
if (date) {
|
||||
sql += " WHERE dateModified>?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return Zotero.DB.columnQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the creatorDataID matching given fields
|
||||
*
|
||||
|
|
|
@ -35,6 +35,33 @@ Zotero.DataObjects = function (object, objectPlural, id, table) {
|
|||
}
|
||||
|
||||
|
||||
this.getOlder = function (date) {
|
||||
if (!date || date.constructor.name != 'Date') {
|
||||
throw ("date must be a JS Date in "
|
||||
+ "Zotero." + this._ZDO_Objects + ".getOlder()")
|
||||
}
|
||||
|
||||
var sql = "SELECT " + this._ZDO_id + " FROM " + this._ZDO_table
|
||||
+ " WHERE dateModified<?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
|
||||
|
||||
this.getNewer = function (date) {
|
||||
if (date && date.constructor.name != 'Date') {
|
||||
throw ("date must be a JS Date in "
|
||||
+ "Zotero." + this._ZDO_Objects + ".getNewer()")
|
||||
}
|
||||
|
||||
var sql = "SELECT " + this._ZDO_id + " FROM " + this._ZDO_table;
|
||||
if (date) {
|
||||
sql += " WHERE dateModified>?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return Zotero.DB.columnQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reloads data for specified items into internal array
|
||||
*
|
||||
|
|
|
@ -32,7 +32,6 @@ Zotero.Items = new function() {
|
|||
this.get = get;
|
||||
this.exist = exist;
|
||||
this.getAll = getAll;
|
||||
this.getUpdated = getUpdated;
|
||||
this.add = add;
|
||||
this.cacheFields = cacheFields;
|
||||
this.erase = erase;
|
||||
|
@ -125,15 +124,6 @@ Zotero.Items = new function() {
|
|||
}
|
||||
|
||||
|
||||
function getUpdated(date) {
|
||||
var s = new Zotero.Search();
|
||||
if (date) {
|
||||
s.addCondition('dateModified', 'isAfter', Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return s.search();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a new item with optional metadata and pass back the primary reference
|
||||
*
|
||||
|
|
|
@ -35,7 +35,6 @@ Zotero.Tags = new function() {
|
|||
this.getID = getID;
|
||||
this.getIDs = getIDs;
|
||||
this.getTypes = getTypes;
|
||||
this.getUpdated = getUpdated;
|
||||
this.getAll = getAll;
|
||||
this.getAllWithinSearch = getAllWithinSearch;
|
||||
this.getTagItems = getTagItems;
|
||||
|
@ -115,16 +114,6 @@ Zotero.Tags = new function() {
|
|||
}
|
||||
|
||||
|
||||
function getUpdated(date) {
|
||||
var sql = "SELECT tagID FROM tags";
|
||||
if (date) {
|
||||
sql += " WHERE dateModified>?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return Zotero.DB.columnQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all tags indexed by tagID
|
||||
*
|
||||
|
|
|
@ -1495,7 +1495,6 @@ Zotero.Searches = new function(){
|
|||
|
||||
this.get = get;
|
||||
this.getAll = getAll;
|
||||
this.getUpdated = getUpdated;
|
||||
this.erase = erase;
|
||||
|
||||
|
||||
|
@ -1525,16 +1524,6 @@ Zotero.Searches = new function(){
|
|||
}
|
||||
|
||||
|
||||
function getUpdated(date) {
|
||||
var sql = "SELECT savedSearchID FROM savedSearches";
|
||||
if (date) {
|
||||
sql += " WHERE dateModified>?";
|
||||
return Zotero.DB.columnQuery(sql, Zotero.Date.dateToSQL(date, true));
|
||||
}
|
||||
return Zotero.DB.columnQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Delete a given saved search from the DB
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,6 @@ Zotero.Sync = new function() {
|
|||
this.init = init;
|
||||
this.getObjectTypeID = getObjectTypeID;
|
||||
this.getObjectTypeName = getObjectTypeName;
|
||||
this.getUpdatedObjects = getUpdatedObjects;
|
||||
this.getDeletedObjects = getDeletedObjects;
|
||||
this.purgeDeletedObjects = purgeDeletedObjects;
|
||||
|
||||
|
@ -78,13 +77,27 @@ Zotero.Sync = new function() {
|
|||
|
||||
|
||||
/**
|
||||
* @param object lastSyncDate JS Date object
|
||||
* @return object { items: [123, 234, ...], creators: [321, 432, ...], ... }
|
||||
* @param {Date} olderThanDate Retrieve objects last updated before this date
|
||||
* @param {Date} newerThanDate Retrieve objects last updated after this date
|
||||
* @return {Object} { items: [123, 234, ...], creators: [321, 432, ...], ... }
|
||||
*/
|
||||
function getUpdatedObjects(lastSyncDate) {
|
||||
if (lastSyncDate && lastSyncDate.constructor.name != 'Date') {
|
||||
throw ('lastSyncDate must be a Date or FALSE in '
|
||||
+ 'Zotero.Sync.getDeletedObjects()')
|
||||
this.getObjectsByDate = function (olderThanDate, newerThanDate) {
|
||||
var funcName = "Zotero.Sync.getObjectsByDate()";
|
||||
if (olderThanDate && olderThanDate.constructor.name != 'Date') {
|
||||
throw ("olderThanDate must be a Date or FALSE in " + funcName)
|
||||
}
|
||||
if (newerThanDate && newerThanDate.constructor.name != 'Date') {
|
||||
throw ("newerThanDate must be a Date or FALSE in " + funcName)
|
||||
}
|
||||
|
||||
// If dates overlap, retrieve all objects
|
||||
if (!olderThanDate && !newerThanDate) {
|
||||
var all = true;
|
||||
}
|
||||
else if (olderThanDate && newerThanDate && olderThanDate > newerThanDate) {
|
||||
olderThanDate = null;
|
||||
newerThanDate = null;
|
||||
var all = true;
|
||||
}
|
||||
|
||||
var updatedIDs = {};
|
||||
|
@ -94,7 +107,25 @@ Zotero.Sync = new function() {
|
|||
|
||||
Zotero.debug("Getting updated local " + types);
|
||||
|
||||
updatedIDs[types] = Zotero[Types].getUpdated(lastSyncDate);
|
||||
if (olderThanDate) {
|
||||
var earlierIDs = Zotero[Types].getOlder(olderThanDate);
|
||||
if (earlierIDs) {
|
||||
updatedIDs[types] = earlierIDs;
|
||||
}
|
||||
}
|
||||
|
||||
if (newerThanDate || all) {
|
||||
var laterIDs = Zotero[Types].getNewer(newerThanDate);
|
||||
if (laterIDs) {
|
||||
if (updatedIDs[types]) {
|
||||
updatedIDs[types].concat(laterIDs);
|
||||
}
|
||||
else {
|
||||
updatedIDs[types] = laterIDs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!updatedIDs[types]) {
|
||||
updatedIDs[types] = [];
|
||||
}
|
||||
|
@ -745,12 +776,26 @@ Zotero.Sync.Server = new function () {
|
|||
try {
|
||||
Zotero.UnresponsiveScriptIndicator.disable();
|
||||
|
||||
var earliestRemoteDate = parseInt(xml.@earliest) ?
|
||||
new Date((xml.@earliest + 43200) * 1000) : false;
|
||||
|
||||
var lastLocalSyncTime = Zotero.Sync.Server.lastLocalSyncTime;
|
||||
var lastLocalSyncDate = lastLocalSyncTime ?
|
||||
new Date(lastLocalSyncTime * 1000) : false;
|
||||
|
||||
var syncSession = new Zotero.Sync.Server.Session;
|
||||
syncSession.uploadIDs.updated = Zotero.Sync.getUpdatedObjects(lastLocalSyncDate);
|
||||
// Fetch old objects not on server (due to a clear) and new
|
||||
// objects added since last sync
|
||||
if (earliestRemoteDate && lastLocalSyncDate) {
|
||||
syncSession.uploadIDs.updated = Zotero.Sync.getObjectsByDate(
|
||||
earliestRemoteDate, lastLocalSyncDate
|
||||
);
|
||||
}
|
||||
// Fetch all local objects
|
||||
else {
|
||||
syncSession.uploadIDs.updated = Zotero.Sync.getObjectsByDate();
|
||||
}
|
||||
|
||||
var deleted = Zotero.Sync.getDeletedObjects(lastLocalSyncDate);
|
||||
if (deleted == -1) {
|
||||
_error('Sync delete log starts after last sync date in Zotero.Sync.Server.sync()');
|
||||
|
|
Loading…
Add table
Reference in a new issue