From 2db41b0adc136df9b026a0890dd31409ec91505d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 27 Apr 2017 22:25:26 -0400 Subject: [PATCH] Don't update various primary fields unnecessarily during save --- .../content/zotero/xpcom/data/dataObject.js | 21 ++++++++++++------- chrome/content/zotero/xpcom/data/item.js | 15 +++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index f7783ba13..cbb76c93c 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -930,14 +930,19 @@ Zotero.DataObject.prototype._saveData = function (env) { var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID; var key = env.key = this._key = this.key ? this.key : this._generateKey(); - env.sqlColumns = [ - 'libraryID', - 'key' - ]; - env.sqlValues = [ - libraryID, - key - ]; + env.sqlColumns = []; + env.sqlValues = []; + + if (env.isNew) { + env.sqlColumns.push( + 'libraryID', + 'key' + ); + env.sqlValues.push( + libraryID, + key + ); + } if (this._changed.primaryData && this._changed.primaryData.version) { env.sqlColumns.push('version'); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 7fcc0cc89..84d076e1f 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1244,14 +1244,10 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { // If available id value, use it -- otherwise we'll use autoincrement var itemID = this._id = this.id ? this.id : Zotero.ID.get('items'); - env.sqlColumns.push( - 'itemTypeID', - 'dateAdded' - ); - env.sqlValues.push( - { int: itemTypeID }, - this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime - ); + if (this._changed.primaryData && this._changed.primaryData.itemTypeID) { + env.sqlColumns.push('itemTypeID'); + env.sqlValues.push({ int: itemTypeID }); + } // If a new item and Date Modified hasn't been provided, or an existing item and // Date Modified hasn't changed from its previous value and skipDateModifiedUpdate wasn't @@ -1271,6 +1267,9 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { } if (isNew) { + env.sqlColumns.push('dateAdded'); + env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime); + env.sqlColumns.unshift('itemID'); env.sqlValues.unshift(parseInt(itemID));