core: use 15s timeout for remote sync

This commit is contained in:
Abdullah Atta
2023-01-13 17:18:44 +05:00
parent d5793e9e4e
commit 15ed1b498a

View File

@@ -109,7 +109,7 @@ class Sync {
this.autoSync = new AutoSync(db, 1000); this.autoSync = new AutoSync(db, 1000);
this.logger = logger.scope("Sync"); this.logger = logger.scope("Sync");
this.syncConnectionMutex = new Mutex(); this.syncConnectionMutex = new Mutex();
this.devicesInSync = new Set(); let remoteSyncTimeout = 0;
const tokenManager = new TokenManager(db.storage); const tokenManager = new TokenManager(db.storage);
this.connection = new signalr.HubConnectionBuilder() this.connection = new signalr.HubConnectionBuilder()
@@ -151,7 +151,10 @@ class Sync {
}); });
this.connection.on("SyncItem", async (payload) => { this.connection.on("SyncItem", async (payload) => {
if (payload.sender) this.devicesInSync.add(payload.sender); clearTimeout(remoteSyncTimeout);
remoteSyncTimeout = setTimeout(() => {
db.eventManager.publish(EVENTS.syncAborted);
}, 15000);
await this.onSyncItem(payload); await this.onSyncItem(payload);
sendSyncProgressEvent( sendSyncProgressEvent(
@@ -162,19 +165,8 @@ class Sync {
); );
}); });
this.connection.on("DeviceDisconnected", (device) => { this.connection.on("RemoteSyncCompleted", (lastSynced) => {
if (device && this.devicesInSync.has(device)) { clearTimeout(remoteSyncTimeout);
db.eventManager.publish(
EVENTS.syncAborted,
"The syncing device was disconnected."
);
this.devicesInSync.delete(device);
}
});
this.connection.on("RemoteSyncCompleted", (lastSynced, sender) => {
if (sender) this.devicesInSync.delete(sender);
this.onRemoteSyncCompleted(lastSynced); this.onRemoteSyncCompleted(lastSynced);
}); });
} }