From 5f60f6043c4be88bede2869c722d24858214e823 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 21 Feb 2009 04:23:50 +0000 Subject: [PATCH] - Fix problem that was causing lots of sync errors on upload, and adjust a previous attempted fix that was making it worse - Should also keep timestamps from going too far into the future when saving many items at once (which they were after my previous fix), though this can still be improved --- chrome/content/zotero/xpcom/data/item.js | 14 ++++---------- chrome/content/zotero/xpcom/db.js | 15 ++++++++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 723de4bbf..ef2de84e8 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1124,16 +1124,10 @@ Zotero.Item.prototype.save = function() { sqlColumns.push('itemTypeID', 'key'); sqlValues.push({ int: this.getField('itemTypeID') }, key); - - if (this.dateAdded) { - sqlColumns.push('dateAdded'); - sqlValues.push(this.dateAdded); - } - - if (this.dateModified) { - sqlColumns.push('dateModified'); - sqlValues.push(this.dateModified); - } + sqlColumns.push('dateAdded'); + sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime); + sqlColumns.push('dateModified'); + sqlValues.push(this.dateModified ? this.dateModified : Zotero.DB.transactionDateTime); // Begin history transaction // No associated id yet, so we use false diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 1eccc5924..b15c58548 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -31,11 +31,17 @@ Zotero.DBConnection = function(dbName) { // JS Date this.__defineGetter__('transactionDate', function () { if (this._transactionDate) { + this._lastTransactionDate = this._transactionDate; return this._transactionDate; } + + Components.utils.reportError("Zotero.DB.transactionDate retrieved with no transaction"); + // Use second granularity rather than millisecond // for comparison purposes - return new Date(Math.floor(new Date / 1000) * 1000); + var d = new Date(Math.floor(new Date / 1000) * 1000); + this._lastTransactionDate = d; + return d; }); // SQL DATETIME this.__defineGetter__('transactionDateTime', function () { @@ -359,7 +365,7 @@ Zotero.DBConnection.prototype.beginTransaction = function () { // Set a timestamp for this transaction this._transactionDate = new Date(Math.floor(new Date / 1000) * 1000); - // If transaction time hasn't changed since last transaction, + // If transaction time hasn't changed since last used transaction time, // add a second -- this is a hack to get around a sync problem when // multiple sync sessions run within the same second if (this._lastTransactionDate && @@ -391,11 +397,10 @@ Zotero.DBConnection.prototype.commitTransaction = function () { else { this._debug('Committing transaction',5); + // Clear transaction time if (this._transactionDate) { - this._lastTransactionDate = this._transactionDate; + this._transactionDate = null; } - // Clear transaction timestamp - this._transactionDate = null; try { db.commitTransaction();