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

This commit is contained in:
Dan Stillman 2013-08-12 16:31:28 -04:00
parent a29f8ea852
commit 9f24dcdb44
2 changed files with 17 additions and 12 deletions

View file

@ -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);
return Zotero.DB.columnQueryAsync(sql, sqlParams)
.then(function (collectionIDs) {
return asIDs ? collectionIDs : Zotero.Collections.get(collectionIDs);
});
if (asIDs) {
return collectionIDs;
}
return Zotero.Collections.get(collectionIDs);
}

View file

@ -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();
}
}