Deasyncification 🔙 😢
While trying to get translation and citing working with asynchronously generated data, we realized that drag-and-drop support was going to be...problematic. Firefox only supports synchronous methods for providing drag data (unlike, it seems, the DataTransferItem interface supported by Chrome), which means that we'd need to preload all relevant data on item selection (bounded by export.quickCopy.dragLimit) and keep the translate/cite methods synchronous (or maintain two separate versions). What we're trying instead is doing what I said in #518 we weren't going to do: loading most object data on startup and leaving many more functions synchronous. Essentially, this takes the various load*() methods described in #518, moves them to startup, and makes them operate on entire libraries rather than individual objects. The obvious downside here (other than undoing much of the work of the last many months) is that it increases startup time, potentially quite a lot for larger libraries. On my laptop, with a 3,000-item library, this adds about 3 seconds to startup time. I haven't yet tested with larger libraries. But I'm hoping that we can optimize this further to reduce that delay. Among other things, this is loading data for all libraries, when it should be able to load data only for the library being viewed. But this is also fundamentally just doing some SELECT queries and storing the results, so it really shouldn't need to be that slow (though performance may be bounded a bit here by XPCOM overhead). If we can make this fast enough, it means that third-party plugins should be able to remain much closer to their current designs. (Some things, including saving, will still need to be made asynchronous.)
This commit is contained in:
parent
d871e2540b
commit
daf4a8fe4d
57 changed files with 1648 additions and 1607 deletions
|
@ -143,8 +143,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
var item = new Zotero.Item("attachment");
|
||||
item.attachmentLinkMode = 'imported_file';
|
||||
item.attachmentPath = 'storage:test.txt';
|
||||
item.attachmentSyncState = "to_download";
|
||||
yield item.saveTx();
|
||||
yield Zotero.Sync.Storage.Local.setSyncState(item.id, "to_download");
|
||||
|
||||
this.httpd.registerPathHandler(
|
||||
`/users/1/items/${item.key}/file`,
|
||||
|
@ -175,8 +175,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
var item = new Zotero.Item("attachment");
|
||||
item.attachmentLinkMode = 'imported_file';
|
||||
item.attachmentPath = 'storage:test.txt';
|
||||
item.attachmentSyncState = "to_download";
|
||||
yield item.saveTx();
|
||||
yield Zotero.Sync.Storage.Local.setSyncState(item.id, "to_download");
|
||||
|
||||
this.httpd.registerPathHandler(
|
||||
`/users/1/items/${item.key}/file`,
|
||||
|
@ -208,8 +208,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
item.attachmentPath = 'storage:test.txt';
|
||||
// TODO: Test binary data
|
||||
var text = Zotero.Utilities.randomString();
|
||||
item.attachmentSyncState = "to_download";
|
||||
yield item.saveTx();
|
||||
yield Zotero.Sync.Storage.Local.setSyncState(item.id, "to_download");
|
||||
|
||||
var mtime = "1441252524905";
|
||||
var md5 = Zotero.Utilities.Internal.md5(text)
|
||||
|
@ -553,11 +553,11 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
assert.isFalse(result.syncRequired);
|
||||
|
||||
// Check local objects
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedModificationTime(item1.id)), mtime1);
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedHash(item1.id)), hash1);
|
||||
assert.equal(item1.attachmentSyncedModificationTime, mtime1);
|
||||
assert.equal(item1.attachmentSyncedHash, hash1);
|
||||
assert.equal(item1.version, 10);
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedModificationTime(item2.id)), mtime2);
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedHash(item2.id)), hash2);
|
||||
assert.equal(item2.attachmentSyncedModificationTime, mtime2);
|
||||
assert.equal(item2.attachmentSyncedHash, hash2);
|
||||
assert.equal(item2.version, 15);
|
||||
})
|
||||
|
||||
|
@ -569,7 +569,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
var item = yield Zotero.Attachments.importFromFile({ file: file });
|
||||
item.version = 5;
|
||||
yield item.saveTx();
|
||||
var json = yield item.toJSON();
|
||||
var json = item.toJSON();
|
||||
yield Zotero.Sync.Data.Local.saveCacheObject('item', item.libraryID, json);
|
||||
|
||||
var mtime = yield item.attachmentModificationTime;
|
||||
|
@ -615,8 +615,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
assert.isFalse(result.syncRequired);
|
||||
|
||||
// Check local objects
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedModificationTime(item.id)), mtime);
|
||||
assert.equal((yield Zotero.Sync.Storage.Local.getSyncedHash(item.id)), hash);
|
||||
assert.equal(item.attachmentSyncedModificationTime, mtime);
|
||||
assert.equal(item.attachmentSyncedHash, hash);
|
||||
assert.equal(item.version, newVersion);
|
||||
})
|
||||
})
|
||||
|
@ -635,7 +635,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
item.synced = true;
|
||||
yield item.saveTx();
|
||||
|
||||
var itemJSON = yield item.toResponseJSON();
|
||||
var itemJSON = item.toResponseJSON();
|
||||
itemJSON.data.mtime = yield item.attachmentModificationTime;
|
||||
itemJSON.data.md5 = yield item.attachmentHash;
|
||||
|
||||
|
@ -645,9 +645,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
// storage directory was transferred, the mtime doesn't match, but the file was
|
||||
// never downloaded), but there's no difference in behavior
|
||||
var dbHash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Sync.Storage.Local.setSyncedHash(item.id, dbHash)
|
||||
});
|
||||
item.attachmentSyncedHash = dbHash;
|
||||
yield item.saveTx({ skipAll: true });
|
||||
|
||||
server.respond(function (req) {
|
||||
if (req.method == "POST"
|
||||
|
@ -674,10 +673,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
var result = yield zfs._processUploadFile({
|
||||
name: item.libraryKey
|
||||
});
|
||||
yield assert.eventually.equal(
|
||||
Zotero.Sync.Storage.Local.getSyncedHash(item.id),
|
||||
(yield item.attachmentHash)
|
||||
);
|
||||
assert.equal(item.attachmentSyncedHash, (yield item.attachmentHash));
|
||||
assert.isFalse(result.localChanges);
|
||||
assert.isFalse(result.remoteChanges);
|
||||
assert.isFalse(result.syncRequired);
|
||||
|
@ -697,7 +693,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
yield item.saveTx();
|
||||
|
||||
var fileHash = yield item.attachmentHash;
|
||||
var itemJSON = yield item.toResponseJSON();
|
||||
var itemJSON = item.toResponseJSON();
|
||||
itemJSON.data.md5 = 'aaaaaaaaaaaaaaaaaaaaaaaa'
|
||||
|
||||
server.respond(function (req) {
|
||||
|
@ -725,11 +721,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
var result = yield zfs._processUploadFile({
|
||||
name: item.libraryKey
|
||||
});
|
||||
yield assert.eventually.isNull(Zotero.Sync.Storage.Local.getSyncedHash(item.id));
|
||||
yield assert.eventually.equal(
|
||||
Zotero.Sync.Storage.Local.getSyncState(item.id),
|
||||
Zotero.Sync.Storage.Local.SYNC_STATE_IN_CONFLICT
|
||||
);
|
||||
assert.isNull(item.attachmentSyncedHash);
|
||||
assert.equal(item.attachmentSyncState, Zotero.Sync.Storage.Local.SYNC_STATE_IN_CONFLICT);
|
||||
assert.isFalse(result.localChanges);
|
||||
assert.isFalse(result.remoteChanges);
|
||||
assert.isFalse(result.syncRequired);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue