From e584dbf5ddbfa13c5a83fffadf61aedd73e98e00 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 10 May 2015 04:18:40 -0400 Subject: [PATCH] Wait for items list to refresh before handling notifications This fixes an error if New Item is used before the items list has loaded. --- .../zotero/xpcom/collectionTreeView.js | 6 +- chrome/content/zotero/xpcom/itemTreeView.js | 217 ++++++++++-------- 2 files changed, 124 insertions(+), 99 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 951daf0a9..f003c64c2 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -2141,9 +2141,11 @@ Zotero.CollectionTreeCache = { "clear": Zotero.Promise.coroutine(function* () { this.lastTreeRow = null; this.lastSearch = null; - yield Zotero.DB.waitForTransaction(); if(this.lastTempTable) { - yield Zotero.DB.queryAsync("DROP TABLE IF EXISTS " + this.lastTempTable); + // Drop the last temp table when we can. We don't wait on this because it can cause a + // deadlock: this waits on open transactions, but a transaction could be waiting on + // ItemTreeView::notify(), which waits on ItemTreeView::refresh(), which calls this. + Zotero.DB.queryTx("DROP TABLE IF EXISTS " + this.lastTempTable).done(); } this.lastTempTable = null; this.lastResults = null; diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 72e097fbc..27968e8af 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -51,6 +51,8 @@ Zotero.ItemTreeView = function (collectionTreeRow, sourcesOnly) { this._cellTextCache = {}; this._itemImages = {}; + this._refreshPromise = Zotero.Promise.resolve(); + this._unregisterID = Zotero.Notifier.registerObserver( this, ['item', 'collection-item', 'item-tag', 'share-items', 'bucket'], 'itemTreeView' ); @@ -289,115 +291,134 @@ Zotero.ItemTreeView.prototype.refresh = Zotero.serial(Zotero.Promise.coroutine(f return false; } - for (let i=0; i