Skip to content

Commit

Permalink
Don't update various primary fields unnecessarily during save
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Apr 28, 2017
1 parent 7bd8f47 commit 2db41b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
21 changes: 13 additions & 8 deletions chrome/content/zotero/xpcom/data/dataObject.js
Expand Up @@ -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');
Expand Down
15 changes: 7 additions & 8 deletions chrome/content/zotero/xpcom/data/item.js
Expand Up @@ -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
Expand All @@ -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));

Expand Down

0 comments on commit 2db41b0

Please sign in to comment.