From 70d9b9870c895dbc0c71138ab7ed747edcfd1753 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 31 Jul 2015 04:03:09 -0400 Subject: [PATCH] Fix a few small data layer bugs, and tidy up a little I don't think these were triggered by any client code, but I found them while porting code to the server. --- .../content/zotero/xpcom/data/collection.js | 67 ++++++++--- .../content/zotero/xpcom/data/dataObject.js | 28 +++-- .../content/zotero/xpcom/data/dataObjects.js | 10 +- chrome/content/zotero/xpcom/data/item.js | 59 +++++----- chrome/content/zotero/xpcom/search.js | 105 ++++++++++++------ test/tests/dataObjectTest.js | 79 +++++++++---- 6 files changed, 229 insertions(+), 119 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 61e38fe31..719aba990 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -99,24 +99,57 @@ Zotero.Collection.prototype.getName = function() { * Populate collection data from a database row */ Zotero.Collection.prototype.loadFromRow = function(row) { - for each(let col in this.ObjectsClass.primaryFields) { - if (row[col] === undefined) { - Zotero.debug('Skipping missing collection field ' + col); + var primaryFields = this._ObjectsClass.primaryFields; + for (let i=0; i this._changed[dataType]); + if (changed.length == 1 + && changed[0] == 'primaryData' + && this._changed.primaryData.synced + && this._previousData.synced == this._synced) { + return false; + } + return !!changed.length; +} + + /** * Clears log of changed values * @param {String} [dataType] data type/field to clear. Defaults to clearing everything @@ -904,17 +919,6 @@ Zotero.DataObject.prototype.saveTx = function (options) { } -Zotero.DataObject.prototype.hasChanged = function() { - var changed = Object.keys(this._changed).filter(dataType => this._changed[dataType]); - if (changed.length == 1 - && changed[0] == 'primaryData' - && this._changed.primaryData.synced - && this._previousData.synced == this._synced) { - return false; - } - return !!changed.length; -} - Zotero.DataObject.prototype._initSave = Zotero.Promise.coroutine(function* (env) { // Default to user library if not specified if (this.libraryID === null) { diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js index 952f7c456..c6f423b22 100644 --- a/chrome/content/zotero/xpcom/data/dataObjects.js +++ b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -277,8 +277,8 @@ Zotero.DataObjects.prototype.getByLibraryAndKeyAsync = Zotero.Promise.coroutine( }); -Zotero.DataObjects.prototype.exists = function (itemID) { - return !!this.getLibraryAndKeyFromID(itemID); +Zotero.DataObjects.prototype.exists = function (id) { + return !!this.getLibraryAndKeyFromID(id); } @@ -383,7 +383,8 @@ Zotero.DataObjects.prototype.registerObject = function (obj) { var libraryID = obj.libraryID; var key = obj.key; - Zotero.debug("Registering " + this._ZDO_object + " " + id + " as " + libraryID + "/" + key); + Zotero.debug("Registering " + this._ZDO_object + " " + id + + " as " + libraryID + "/" + key); if (!this._objectIDs[libraryID]) { this._objectIDs[libraryID] = {}; } @@ -568,8 +569,7 @@ Zotero.DataObjects.prototype._load = Zotero.Promise.coroutine(function* (library obj = new Zotero[this._ZDO_Object]; obj.loadFromRow(rowObj, true); if (!options || !options.noCache) { - this._objectCache[id] = obj; - obj._inCache = true; + this.registerObject(obj); } } loaded[id] = obj; diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 1cad804d8..f1a862cee 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -316,23 +316,26 @@ Zotero.Item.prototype._parseRowData = function(row) { for (let i=0; i