- 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
This commit is contained in:
Dan Stillman 2009-02-21 04:23:50 +00:00
parent d7d4bc01d7
commit 5f60f6043c
2 changed files with 14 additions and 15 deletions

View file

@ -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

View file

@ -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();