commit 5f60f6043c4be88bede2869c722d24858214e823
parent d7d4bc01d757cf23f71aaa81744440e8c6bdd981
Author: Dan Stillman <dstillman@zotero.org>
Date: Sat, 21 Feb 2009 04:23:50 +0000
- 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
Diffstat:
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
@@ -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
@@ -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();