Drastically speed up moving items to the trash

E.g., moving 3,600 items to the trash now takes 4 seconds instead of 62

Instead of saving each item, update internal state and database directly
(which is more brittle but worth it). Also avoid unnecessary sorting
after removing an item from the items tree.
This commit is contained in:
Dan Stillman 2017-02-08 21:53:29 -05:00
parent 58edb3143e
commit 3a0e0cb088
5 changed files with 85 additions and 15 deletions

View file

@ -87,6 +87,28 @@ describe("Zotero.Items", function () {
})
})
describe("#trash()", function () {
it("should send items to the trash", function* () {
var items = [];
items.push(
(yield createDataObject('item')),
(yield createDataObject('item')),
(yield createDataObject('item'))
);
var ids = items.map(item => item.id);
yield Zotero.Items.trashTx(ids);
items.forEach(item => {
assert.isTrue(item.deleted);
assert.isFalse(item.hasChanged());
});
assert.equal((yield Zotero.DB.valueQueryAsync(
`SELECT COUNT(*) FROM deletedItems WHERE itemID IN (${ids})`
)), 3);
});
});
describe("#emptyTrash()", function () {
it("should delete items in the trash", function* () {
var item1 = createUnsavedDataObject('item');