www

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

commit 9f24dcdb44892ef7431f02d41bc5634cf2a58f3b
parent a29f8ea8525713ddcc920f64e121ccfd3cf5fe30
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 12 Aug 2013 16:31:28 -0400

Use async DB query for collections-containing-an-item

Diffstat:
Mchrome/content/zotero/xpcom/data/collections.js | 18++++++++++--------
Mchrome/content/zotero/zoteroPane.js | 11+++++++----
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/collections.js b/chrome/content/zotero/xpcom/data/collections.js @@ -33,7 +33,6 @@ Zotero.Collections = new function() { this.get = get; this.add = add; - this.getCollectionsContainingItems = getCollectionsContainingItems; this.erase = erase; /* @@ -64,7 +63,12 @@ Zotero.Collections = new function() { } - function getCollectionsContainingItems(itemIDs, asIDs) { + this.getCollectionsContainingItems = function (itemIDs, asIDs) { + // If an unreasonable number of items, don't try + if (itemIDs.length > 100) { + return Q([]); + } + var sql = "SELECT collectionID FROM collections WHERE "; var sqlParams = []; for each(var id in itemIDs) { @@ -73,13 +77,11 @@ Zotero.Collections = new function() { sqlParams.push(id); } sql = sql.substring(0, sql.length - 5); - var collectionIDs = Zotero.DB.columnQuery(sql, sqlParams); - - if (asIDs) { - return collectionIDs; - } + return Zotero.DB.columnQueryAsync(sql, sqlParams) + .then(function (collectionIDs) { + return asIDs ? collectionIDs : Zotero.Collections.get(collectionIDs); + }); - return Zotero.Collections.get(collectionIDs); } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -536,10 +536,13 @@ var ZoteroPane = new function() function setHighlightedRowsCallback() { var itemIDs = ZoteroPane_Local.getSelectedItems(true); if (itemIDs && itemIDs.length) { - var collectionIDs = Zotero.Collections.getCollectionsContainingItems(itemIDs, true); - if (collectionIDs) { - ZoteroPane_Local.collectionsView.setHighlightedRows(collectionIDs); - } + Zotero.Collections.getCollectionsContainingItems(itemIDs, true) + .then(function (collectionIDs) { + if (collectionIDs) { + ZoteroPane_Local.collectionsView.setHighlightedRows(collectionIDs); + } + }) + .done(); } }