www

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

commit 4ee5ab34531b445dc547e5fa0839db212c7841b9
parent d842779cae5d1197594f7d1254975528f3699520
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon,  4 Nov 2013 22:45:20 -0500

Remove Zotero.wait() from Zotero.Collection.addItems

Since this is inside a transaction, it could potentially cause more
state check errors

Diffstat:
Mchrome/content/zotero/xpcom/data/collection.js | 95+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 52 insertions(+), 43 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js @@ -693,55 +693,64 @@ Zotero.Collection.prototype.addItems = function(itemIDs) { var notifierPairs = []; - for (var i=0; i<itemIDs.length; i++) { - var itemID = itemIDs[i]; - if (current && current.indexOf(itemID) != -1) { - Zotero.debug("Item " + itemID + " already a child of collection " - + this.id + " in Zotero.Collection.addItems()"); - continue; - } - - if (!Zotero.Items.get(itemID)) { - Zotero.DB.rollbackTransaction(); - throw(itemID + ' is not a valid item id'); - } - - // If we're already above the max, just increment - if (nextOrderIndex>max) { - nextOrderIndex++; - } - else { - selectStatement.bindInt32Parameter(0, this.id); - selectStatement.executeStep(); - nextOrderIndex = selectStatement.getInt32(0); - selectStatement.reset(); - } - - insertStatement.bindInt32Parameter(0, this.id); - insertStatement.bindInt32Parameter(1, itemID); - insertStatement.bindInt32Parameter(2, nextOrderIndex); - - try { - insertStatement.execute(); - } - catch(e) { - var errMsg = Zotero.DB.getLastErrorString() - + " (" + this.id + "," + itemID + "," + nextOrderIndex + ")"; - throw (e + ' [ERROR: ' + errMsg + ']'); + var reenableScriptIndicator = false; + if(itemIDs.length > 25) { + // Disable unresponsive script indicator for long lists + // Re-enable later only if it wasn't disabled before + reenableScriptIndicator = Zotero.UnresponsiveScriptIndicator.disable(); + } + + try { + for (var i=0; i<itemIDs.length; i++) { + var itemID = itemIDs[i]; + if (current && current.indexOf(itemID) != -1) { + Zotero.debug("Item " + itemID + " already a child of collection " + + this.id + " in Zotero.Collection.addItems()"); + continue; + } + + if (!Zotero.Items.get(itemID)) { + Zotero.DB.rollbackTransaction(); + throw(itemID + ' is not a valid item id'); + } + + // If we're already above the max, just increment + if (nextOrderIndex>max) { + nextOrderIndex++; + } + else { + selectStatement.bindInt32Parameter(0, this.id); + selectStatement.executeStep(); + nextOrderIndex = selectStatement.getInt32(0); + selectStatement.reset(); + } + + insertStatement.bindInt32Parameter(0, this.id); + insertStatement.bindInt32Parameter(1, itemID); + insertStatement.bindInt32Parameter(2, nextOrderIndex); + + try { + insertStatement.execute(); + } + catch(e) { + var errMsg = Zotero.DB.getLastErrorString() + + " (" + this.id + "," + itemID + "," + nextOrderIndex + ")"; + throw (e + ' [ERROR: ' + errMsg + ']'); + } + + notifierPairs.push(this.id + '-' + itemID); } - notifierPairs.push(this.id + '-' + itemID); + sql = "UPDATE collections SET dateModified=?, clientDateModified=? WHERE collectionID=?"; + Zotero.DB.query(sql, [Zotero.DB.transactionDateTime, Zotero.DB.transactionDateTime, this.id]); - if ((i % 25) == 0 && Zotero.locked) { - Zotero.wait(); + Zotero.DB.commitTransaction(); + } finally { + if(reenableScriptIndicator) { + Zotero.UnresponsiveScriptIndicator.enable(); } } - sql = "UPDATE collections SET dateModified=?, clientDateModified=? WHERE collectionID=?"; - Zotero.DB.query(sql, [Zotero.DB.transactionDateTime, Zotero.DB.transactionDateTime, this.id]); - - Zotero.DB.commitTransaction(); - Zotero.Collections.reload(this.id); Zotero.Notifier.trigger('add', 'collection-item', notifierPairs); }