Dramatically speed up adding/removing items to/from collections

This commit is contained in:
Dan Stillman 2007-04-02 14:22:17 +00:00
parent eef19de220
commit 1f3f9ea2e1
3 changed files with 46 additions and 10 deletions

View File

@ -647,16 +647,22 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
} }
else if (dataType == 'zotero/item') { else if (dataType == 'zotero/item') {
var ids = data.data.split(','); var ids = data.data.split(',');
var targetCollection = this._getItemAtRow(row).ref; if (ids.length < 1) {
for each(var id in ids) return;
{ }
var item = Zotero.Items.get(id);
var toAdd = [];
for (var i=0; i<ids.length; i++) {
var item = Zotero.Items.get(ids[i]);
// Only accept top-level items // Only accept top-level items
if (item.isRegularItem() || !item.getSource()) if (item.isRegularItem() || !item.getSource()) {
{ toAdd.push(ids[i]);
targetCollection.addItem(id);
} }
} }
if (toAdd.length > 0) {
this._getItemAtRow(row).ref.addItems(toAdd);
}
} }
else if (dataType == 'text/x-moz-url') { else if (dataType == 'text/x-moz-url') {
var url = data.data.split("\n")[0]; var url = data.data.split("\n")[0];

View File

@ -3013,6 +3013,22 @@ Zotero.Collection.prototype.addItem = function(itemID){
} }
/**
* Add multiple items to the collection in batch
*/
Zotero.Collection.prototype.addItems = function(itemIDs) {
if (!itemIDs || !itemIDs.length) {
return;
}
Zotero.DB.beginTransaction();
for (var i=0; i<itemIDs.length; i++) {
this.addItem(itemIDs[i]);
}
Zotero.DB.commitTransaction();
}
/** /**
* Remove an item from the collection (does not delete item from library) * Remove an item from the collection (does not delete item from library)
**/ **/
@ -3032,6 +3048,22 @@ Zotero.Collection.prototype.removeItem = function(itemID){
} }
/**
* Remove multiple items from the collection in batch
* (does not delete item from library)
*/
Zotero.Collection.prototype.removeItems = function(itemIDs) {
if (!itemIDs || !itemIDs.length) {
return;
}
Zotero.DB.beginTransaction();
for (var i=0; i<itemIDs.length; i++) {
this.removeItem(itemIDs[i]);
}
Zotero.DB.commitTransaction();
}
/** /**
* Check if an item belongs to the collection * Check if an item belongs to the collection
**/ **/

View File

@ -992,9 +992,7 @@ Zotero.ItemTreeView.prototype.deleteSelection = function(eraseChildren, force)
Zotero.Items.erase(ids, eraseChildren); Zotero.Items.erase(ids, eraseChildren);
} }
else if (this._itemGroup.isCollection()) { else if (this._itemGroup.isCollection()) {
for each(var id in ids) { this._itemGroup.ref.removeItems(ids);
this._itemGroup.ref.removeItem(id);
}
} }
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();
} }