Fix 100% CPU usage with pane open (since 9e356a7e6
)
And make Zotero.Item.prototype.fileExists() check the file regardless of whether there's a cached state.
This commit is contained in:
parent
3703bf0423
commit
493d37d1c7
|
@ -2090,6 +2090,7 @@ Zotero.Item.prototype.getFilePathAsync = Zotero.Promise.coroutine(function* () {
|
|||
return false;
|
||||
}
|
||||
|
||||
this._updateAttachmentStates(true);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -2215,10 +2216,6 @@ Zotero.Item.prototype.getFilename = function () {
|
|||
* This is updated only initially and on subsequent getFilePathAsync() calls.
|
||||
*/
|
||||
Zotero.Item.prototype.fileExists = Zotero.Promise.coroutine(function* () {
|
||||
if (this._fileExists !== null) {
|
||||
return this._fileExists;
|
||||
}
|
||||
|
||||
if (!this.isAttachment()) {
|
||||
throw new Error("Zotero.Item.fileExists() can only be called on attachment items");
|
||||
}
|
||||
|
|
|
@ -616,6 +616,57 @@ describe("Zotero.Item", function () {
|
|||
})
|
||||
})
|
||||
|
||||
|
||||
describe("#getBestAttachmentState()", function () {
|
||||
it("should cache state for an existing file", function* () {
|
||||
var parentItem = yield createDataObject('item');
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
var childItem = yield Zotero.Attachments.importFromFile({
|
||||
file,
|
||||
parentItemID: parentItem.id
|
||||
});
|
||||
yield parentItem.getBestAttachmentState();
|
||||
assert.equal(parentItem.getBestAttachmentStateCached(), 1);
|
||||
})
|
||||
|
||||
it("should cache state for a missing file", function* () {
|
||||
var parentItem = yield createDataObject('item');
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
var childItem = yield Zotero.Attachments.importFromFile({
|
||||
file,
|
||||
parentItemID: parentItem.id
|
||||
});
|
||||
let path = yield childItem.getFilePathAsync();
|
||||
yield OS.File.remove(path);
|
||||
yield parentItem.getBestAttachmentState();
|
||||
assert.equal(parentItem.getBestAttachmentStateCached(), -1);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("#fileExists()", function () {
|
||||
it("should cache state for an existing file", function* () {
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
var item = yield Zotero.Attachments.importFromFile({ file });
|
||||
yield item.fileExists();
|
||||
assert.equal(item.fileExistsCached(), true);
|
||||
})
|
||||
|
||||
it("should cache state for a missing file", function* () {
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
var item = yield Zotero.Attachments.importFromFile({ file });
|
||||
let path = yield item.getFilePathAsync();
|
||||
yield OS.File.remove(path);
|
||||
yield item.fileExists();
|
||||
assert.equal(item.fileExistsCached(), false);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("#setTags", function () {
|
||||
it("should save an array of tags in API JSON format", function* () {
|
||||
var tags = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user