Don't load note/attachments counts as primary data
Zotero.Item::numNotes()/numAttachments() now require 'childItems' to have been loaded. Fixes #1301, Slow startup with many items in trash
This commit is contained in:
parent
687f86af71
commit
05d74c4cac
4 changed files with 92 additions and 98 deletions
|
@ -555,6 +555,34 @@ describe("Zotero.Item", function () {
|
|||
});
|
||||
})
|
||||
|
||||
|
||||
describe("#numAttachments()", function () {
|
||||
it("should include child attachments", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
var attachment = yield importFileAttachment('test.png', { parentID: item.id });
|
||||
assert.equal(item.numAttachments(), 1);
|
||||
});
|
||||
|
||||
it("shouldn't include trashed child attachments by default", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield importFileAttachment('test.png', { parentID: item.id });
|
||||
var attachment = yield importFileAttachment('test.png', { parentID: item.id });
|
||||
attachment.deleted = true;
|
||||
yield attachment.saveTx();
|
||||
assert.equal(item.numAttachments(), 1);
|
||||
});
|
||||
|
||||
it("should include trashed child attachments if includeTrashed=true", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield importFileAttachment('test.png', { parentID: item.id });
|
||||
var attachment = yield importFileAttachment('test.png', { parentID: item.id });
|
||||
attachment.deleted = true;
|
||||
yield attachment.saveTx();
|
||||
assert.equal(item.numAttachments(true), 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("#getAttachments()", function () {
|
||||
it("#should return child attachments", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
|
@ -618,6 +646,49 @@ describe("Zotero.Item", function () {
|
|||
});
|
||||
})
|
||||
|
||||
describe("#numNotes()", function () {
|
||||
it("should include child notes", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
assert.equal(item.numNotes(), 2);
|
||||
});
|
||||
|
||||
it("shouldn't include trashed child notes by default", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id, deleted: true });
|
||||
assert.equal(item.numNotes(), 1);
|
||||
});
|
||||
|
||||
it("should include trashed child notes with includeTrashed", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id, deleted: true });
|
||||
assert.equal(item.numNotes(true), 2);
|
||||
});
|
||||
|
||||
it("should include child attachment notes with includeEmbedded", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
var attachment = yield importFileAttachment('test.png', { parentID: item.id });
|
||||
attachment.setNote('test');
|
||||
yield attachment.saveTx();
|
||||
yield item.loadDataType('childItems');
|
||||
assert.equal(item.numNotes(false, true), 2);
|
||||
});
|
||||
|
||||
it("shouldn't include empty child attachment notes with includeEmbedded", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
yield createDataObject('item', { itemType: 'note', parentID: item.id });
|
||||
var attachment = yield importFileAttachment('test.png', { parentID: item.id });
|
||||
assert.equal(item.numNotes(false, true), 1);
|
||||
});
|
||||
|
||||
// TODO: Fix numNotes(false, true) updating after child attachment note is added or removed
|
||||
});
|
||||
|
||||
|
||||
describe("#getNotes()", function () {
|
||||
it("#should return child notes", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue