www

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

commit b1fc6ac67cbb284f619a71cccb2e66c943147651
parent 1711ba4dd4ec0387f94ea74f4ac4ee8326ea2caf
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu,  9 Mar 2017 03:04:41 -0500

Fix (some) crashes switching collections while items are being added

The items list is generated from the database (via search), but new
items may have been added to the database but not yet been registered,
causing unloaded-data errors during sorting. Avoid that by not showing
unregistered items when generating the items list.

Additional protections are necessary -- it's still possible to get
errors, and maybe a crash, if an item has been registered but not yet
fully loaded -- but this addresses the most common one.

Diffstat:
Mchrome/content/zotero/xpcom/collectionTreeRow.js | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -238,9 +238,21 @@ Zotero.CollectionTreeRow.prototype.getItems = Zotero.Promise.coroutine(function* } var ids = yield this.getSearchResults(); + + // Filter out items that exist in the items table (where search results come from) but that haven't + // yet been registered. This helps prevent unloaded-data crashes when switching collections while + // items are being added (e.g., during sync). + var len = ids.length; + ids = ids.filter(id => Zotero.Items.getLibraryAndKeyFromID(id)); + if (len > ids.length) { + let diff = len - ids.length; + Zotero.debug(`Not showing ${diff} unloaded item${diff != 1 ? 's' : ''}`); + } + if (!ids.length) { return [] } + return Zotero.Items.getAsync(ids); });