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 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');

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