Don't update various primary fields unnecessarily during save

This commit is contained in:
Dan Stillman 2017-04-27 22:25:26 -04:00
parent 7bd8f47dac
commit 2db41b0adc
2 changed files with 20 additions and 16 deletions

View file

@ -930,14 +930,19 @@ Zotero.DataObject.prototype._saveData = function (env) {
var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID; var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID;
var key = env.key = this._key = this.key ? this.key : this._generateKey(); var key = env.key = this._key = this.key ? this.key : this._generateKey();
env.sqlColumns = [ env.sqlColumns = [];
env.sqlValues = [];
if (env.isNew) {
env.sqlColumns.push(
'libraryID', 'libraryID',
'key' 'key'
]; );
env.sqlValues = [ env.sqlValues.push(
libraryID, libraryID,
key key
]; );
}
if (this._changed.primaryData && this._changed.primaryData.version) { if (this._changed.primaryData && this._changed.primaryData.version) {
env.sqlColumns.push('version'); env.sqlColumns.push('version');

View file

@ -1244,14 +1244,10 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
// If available id value, use it -- otherwise we'll use autoincrement // If available id value, use it -- otherwise we'll use autoincrement
var itemID = this._id = this.id ? this.id : Zotero.ID.get('items'); var itemID = this._id = this.id ? this.id : Zotero.ID.get('items');
env.sqlColumns.push( if (this._changed.primaryData && this._changed.primaryData.itemTypeID) {
'itemTypeID', env.sqlColumns.push('itemTypeID');
'dateAdded' env.sqlValues.push({ int: itemTypeID });
); }
env.sqlValues.push(
{ int: itemTypeID },
this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime
);
// If a new item and Date Modified hasn't been provided, or an existing item and // 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 // 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) { if (isNew) {
env.sqlColumns.push('dateAdded');
env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime);
env.sqlColumns.unshift('itemID'); env.sqlColumns.unshift('itemID');
env.sqlValues.unshift(parseInt(itemID)); env.sqlValues.unshift(parseInt(itemID));