From 1f3f9ea2e11ffded124cdc7c96b3c6b58cafc151 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 2 Apr 2007 14:22:17 +0000 Subject: [PATCH] Dramatically speed up adding/removing items to/from collections --- .../zotero/xpcom/collectionTreeView.js | 20 ++++++++---- chrome/content/zotero/xpcom/data_access.js | 32 +++++++++++++++++++ chrome/content/zotero/xpcom/itemTreeView.js | 4 +-- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index e4db3c24f..f79a2f84c 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -647,16 +647,22 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient) } else if (dataType == 'zotero/item') { var ids = data.data.split(','); - var targetCollection = this._getItemAtRow(row).ref; - for each(var id in ids) - { - var item = Zotero.Items.get(id); + if (ids.length < 1) { + return; + } + + var toAdd = []; + for (var i=0; i 0) { + this._getItemAtRow(row).ref.addItems(toAdd); + } } else if (dataType == 'text/x-moz-url') { var url = data.data.split("\n")[0]; diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index 9b11a9520..fe3032dca 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -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