www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 2856b71f0bc43b51341d01e241dcbe7bf1109012
parent 78a8e6b6229f4d44a861ba0f0e171c48a2345800
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 12 Aug 2014 03:11:49 -0400

Remove some remaining synchronous queries in data objects

Fixes collection and search saving

Diffstat:
Mchrome/content/zotero/xpcom/data/collection.js | 31++-----------------------------
Mchrome/content/zotero/xpcom/data/item.js | 15---------------
Mchrome/content/zotero/xpcom/search.js | 27+++++++--------------------
3 files changed, 9 insertions(+), 64 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js @@ -90,7 +90,8 @@ Zotero.Collection.prototype._set = function (field, value) { } if (this['_' + field] != value) { - this._prepFieldChange(field); + this._markFieldChange(field, this['_' + field]); + this._changed.primaryData = true; switch (field) { default: @@ -191,20 +192,6 @@ Zotero.Collection.prototype.hasChildItems = function() { return false; } -/** - * Check if collection exists in the database - * - * @return bool TRUE if the collection exists, FALSE if not - */ -Zotero.Collection.prototype.exists = function() { - if (!this.id) { - throw ('collectionID not set in Zotero.Collection.exists()'); - } - - var sql = "SELECT COUNT(*) FROM collections WHERE collectionID=?"; - return !!Zotero.DB.valueQuery(sql, this.id); -} - /** * Returns subcollections of this collection @@ -896,20 +883,6 @@ Zotero.Collection.prototype.addLinkedCollection = Zotero.Promise.coroutine(funct // // Private methods // -Zotero.Collection.prototype._prepFieldChange = function (field) { - if (!this._changed) { - this._changed = {}; - } - this._changed[field] = true; - - // Save a copy of the data before changing - // TODO: only save previous data if collection exists - if (this.id && this.exists() && !this._previousData) { - this._previousData = this.serialize(); - } -} - - Zotero.Collection.prototype.reloadHasChildCollections = Zotero.Promise.coroutine(function* () { var sql = "SELECT COUNT(*) FROM collections WHERE parentCollectionID=?"; this._hasChildCollections = !!(yield Zotero.DB.valueQueryAsync(sql, this.id)); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -155,21 +155,6 @@ Zotero.Item.prototype.isPrimaryField = function (fieldName) { // Public Zotero.Item methods // ////////////////////////////////////////////////////////////////////////////// -/** - * Check if item exists in the database - * - * @return bool TRUE if the item exists, FALSE if not - */ -Zotero.Item.prototype.exists = function() { - if (!this.id) { - throw ('itemID not set in Zotero.Item.exists()'); - } - - var sql = "SELECT COUNT(*) FROM items WHERE itemID=?"; - return !!Zotero.DB.valueQuery(sql, this.id); -} - - /* * Retrieves (and loads from DB, if necessary) an itemData field value * diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js @@ -97,7 +97,8 @@ Zotero.Search.prototype._set = function (field, value) { this._requireData('primaryData'); if (this['_' + field] != value) { - this._prepFieldChange(field); + this._markFieldChange(field, this['_' + field]); + this._changed.primaryData = true; switch (field) { default: @@ -223,7 +224,7 @@ Zotero.Search.prototype.save = Zotero.Promise.coroutine(function* (fixGaps) { if (!isNew) { var sql = "DELETE FROM savedSearchConditions WHERE savedSearchID=?"; - Zotero.DB.query(sql, this.id); + yield Zotero.DB.queryAsync(sql, this.id); } // Close gaps in savedSearchIDs @@ -258,7 +259,7 @@ Zotero.Search.prototype.save = Zotero.Promise.coroutine(function* (fixGaps) { this._conditions[i].value ? this._conditions[i].value : null, this._conditions[i].required ? 1 : null ]; - Zotero.DB.query(sql, sqlParams); + yield Zotero.DB.queryAsync(sql, sqlParams); } @@ -271,7 +272,7 @@ Zotero.Search.prototype.save = Zotero.Promise.coroutine(function* (fixGaps) { if (isNew && this.libraryID) { var groupID = Zotero.Groups.getGroupIDFromLibraryID(this.libraryID); - var group = Zotero.Groups.get(groupID); + var group = yield Zotero.Groups.get(groupID); group.clearSearchCache(); } @@ -665,7 +666,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable var sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE " + "itemID NOT IN (SELECT itemID FROM " + tmpTable + ")"; - var res = yield Zotero.DB.valueQuery(sql); + var res = yield Zotero.DB.valueQueryAsync(sql); var scopeIDs = res ? res.split(",") : []; } // If an ALL search, scan only items from the main search @@ -933,20 +934,6 @@ Zotero.Search.prototype.loadConditions = Zotero.Promise.coroutine(function* (rel }); -Zotero.Search.prototype._prepFieldChange = function (field) { - if (!this._changed) { - this._changed = {}; - } - this._changed[field] = true; - - // Save a copy of the data before changing - // TODO: only save previous data if search exists - if (this.id && this.exists() && !this._previousData) { - this._previousData = this.serialize(); - } -} - - /* * Batch insert */ @@ -1273,7 +1260,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { + 'WHERE fileTypeID IN (' + 'SELECT fileTypeID FROM fileTypes WHERE ' + 'fileTypeID=?)'; - var patterns = Zotero.DB.columnQuery(ftSQL, { int: condition.value }); + var patterns = yield Zotero.DB.columnQueryAsync(ftSQL, { int: condition.value }); if (patterns) { for each(str in patterns) { condSQL += 'mimeType LIKE ? OR ';