diff --git a/server/http_server.ts b/server/http_server.ts index f2cd0463..9e56e44c 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -400,7 +400,7 @@ export class HttpServer { response.body = fileData.data; } catch (e: any) { - console.error("Error GETting file", name, e); + console.error("Error GETting file", name, e.message); response.status = 404; response.body = "Not found"; } diff --git a/web/client.ts b/web/client.ts index d1fabbad..c3e0bdd6 100644 --- a/web/client.ts +++ b/web/client.ts @@ -168,7 +168,7 @@ export class Client { await this.dispatchAppEvent("editor:init"); setInterval(() => { - console.log("Syncing page", this.currentPage, "in background"); + // console.log("Syncing page", this.currentPage, "in background"); try { this.syncService.syncFile(`${this.currentPage!}.md`).catch((e: any) => { console.error("Interval sync error", e); @@ -176,7 +176,7 @@ export class Client { } catch (e: any) { console.error("Interval sync error", e); } - console.log("End of kick-off of background sync of", this.currentPage); + // console.log("End of kick-off of background sync of", this.currentPage); }, pageSyncInterval); } diff --git a/web/sync_service.ts b/web/sync_service.ts index ed74ba1e..16e45324 100644 --- a/web/sync_service.ts +++ b/web/sync_service.ts @@ -84,7 +84,7 @@ export class SyncService { // It's been too long since the last activity, let's consider this one crashed and // reset the sync start state await this.kvStore.del(syncStartTimeKey); - console.info("Sync crashed, resetting"); + console.info("Sync without activity for too long, resetting"); return false; } return true; @@ -125,10 +125,12 @@ export class SyncService { await this.kvStore.set(syncLastActivityKey, Date.now()); } - async registerSyncStop(): Promise { + async registerSyncStop(isFullSync: boolean): Promise { await this.registerSyncProgress(); await this.kvStore.del(syncStartTimeKey); - await this.kvStore.set(syncInitialFullSyncCompletedKey, true); + if (isFullSync) { + await this.kvStore.set(syncInitialFullSyncCompletedKey, true); + } } async getSnapshot(): Promise> { @@ -198,11 +200,11 @@ export class SyncService { (path) => this.isSyncCandidate(path), ); await this.saveSnapshot(snapshot); - await this.registerSyncStop(); + await this.registerSyncStop(true); this.eventHook.dispatchEvent("sync:success", operations); } catch (e: any) { await this.saveSnapshot(snapshot); - await this.registerSyncStop(); + await this.registerSyncStop(false); this.eventHook.dispatchEvent("sync:error", e.message); console.error("Sync error", e.message); } @@ -211,9 +213,9 @@ export class SyncService { // Syncs a single file async syncFile(name: string) { - console.log("About to sync file", name); + // console.log("Checking if we can sync file", name); if (!this.isSyncCandidate(name)) { - console.log("Info not a sync candidate", name); + console.info("Requested sync, but not a sync candidate", name); return; } if (await this.isSyncing()) { @@ -233,7 +235,8 @@ export class SyncService { "File marked as no sync, skipping sync in this cycle", name, ); - await this.registerSyncStop(); + await this.registerSyncStop(false); + // Jumping out, not saving snapshot nor triggering a sync event, because we did nothing return; } localHash = localMeta.lastModified; @@ -251,15 +254,17 @@ export class SyncService { } await this.spaceSync.syncFile(snapshot, name, localHash, remoteHash); - this.eventHook.dispatchEvent("sync:success"); - console.log("File successfully synced", name); + this.eventHook.dispatchEvent("sync:success").catch(console.error); + // console.log("File successfully synced", name); } catch (e: any) { - this.eventHook.dispatchEvent("sync:error", e.message); + this.eventHook.dispatchEvent("sync:error", e.message).catch( + console.error, + ); console.error("Sync error", e); } await this.saveSnapshot(snapshot); - await this.registerSyncStop(); - console.log("And done with file sync for", name); + await this.registerSyncStop(false); + // console.log("And done with file sync for", name); } async saveSnapshot(snapshot: Map) {