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.
This commit is contained in:
Dan Stillman 2017-03-09 03:04:41 -05:00
parent 1711ba4dd4
commit b1fc6ac67c

View file

@ -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);
});