1
0

Dial down excessive debug logging

This commit is contained in:
Zef Hemel 2023-08-10 16:09:28 +02:00
parent c13f7edb65
commit c6fce524e6
3 changed files with 21 additions and 16 deletions

View File

@ -400,7 +400,7 @@ export class HttpServer {
response.body = fileData.data; response.body = fileData.data;
} catch (e: any) { } catch (e: any) {
console.error("Error GETting file", name, e); console.error("Error GETting file", name, e.message);
response.status = 404; response.status = 404;
response.body = "Not found"; response.body = "Not found";
} }

View File

@ -168,7 +168,7 @@ export class Client {
await this.dispatchAppEvent("editor:init"); await this.dispatchAppEvent("editor:init");
setInterval(() => { setInterval(() => {
console.log("Syncing page", this.currentPage, "in background"); // console.log("Syncing page", this.currentPage, "in background");
try { try {
this.syncService.syncFile(`${this.currentPage!}.md`).catch((e: any) => { this.syncService.syncFile(`${this.currentPage!}.md`).catch((e: any) => {
console.error("Interval sync error", e); console.error("Interval sync error", e);
@ -176,7 +176,7 @@ export class Client {
} catch (e: any) { } catch (e: any) {
console.error("Interval sync error", e); 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); }, pageSyncInterval);
} }

View File

@ -84,7 +84,7 @@ export class SyncService {
// It's been too long since the last activity, let's consider this one crashed and // It's been too long since the last activity, let's consider this one crashed and
// reset the sync start state // reset the sync start state
await this.kvStore.del(syncStartTimeKey); await this.kvStore.del(syncStartTimeKey);
console.info("Sync crashed, resetting"); console.info("Sync without activity for too long, resetting");
return false; return false;
} }
return true; return true;
@ -125,10 +125,12 @@ export class SyncService {
await this.kvStore.set(syncLastActivityKey, Date.now()); await this.kvStore.set(syncLastActivityKey, Date.now());
} }
async registerSyncStop(): Promise<void> { async registerSyncStop(isFullSync: boolean): Promise<void> {
await this.registerSyncProgress(); await this.registerSyncProgress();
await this.kvStore.del(syncStartTimeKey); await this.kvStore.del(syncStartTimeKey);
await this.kvStore.set(syncInitialFullSyncCompletedKey, true); if (isFullSync) {
await this.kvStore.set(syncInitialFullSyncCompletedKey, true);
}
} }
async getSnapshot(): Promise<Map<string, SyncStatusItem>> { async getSnapshot(): Promise<Map<string, SyncStatusItem>> {
@ -198,11 +200,11 @@ export class SyncService {
(path) => this.isSyncCandidate(path), (path) => this.isSyncCandidate(path),
); );
await this.saveSnapshot(snapshot); await this.saveSnapshot(snapshot);
await this.registerSyncStop(); await this.registerSyncStop(true);
this.eventHook.dispatchEvent("sync:success", operations); this.eventHook.dispatchEvent("sync:success", operations);
} catch (e: any) { } catch (e: any) {
await this.saveSnapshot(snapshot); await this.saveSnapshot(snapshot);
await this.registerSyncStop(); await this.registerSyncStop(false);
this.eventHook.dispatchEvent("sync:error", e.message); this.eventHook.dispatchEvent("sync:error", e.message);
console.error("Sync error", e.message); console.error("Sync error", e.message);
} }
@ -211,9 +213,9 @@ export class SyncService {
// Syncs a single file // Syncs a single file
async syncFile(name: string) { async syncFile(name: string) {
console.log("About to sync file", name); // console.log("Checking if we can sync file", name);
if (!this.isSyncCandidate(name)) { if (!this.isSyncCandidate(name)) {
console.log("Info not a sync candidate", name); console.info("Requested sync, but not a sync candidate", name);
return; return;
} }
if (await this.isSyncing()) { if (await this.isSyncing()) {
@ -233,7 +235,8 @@ export class SyncService {
"File marked as no sync, skipping sync in this cycle", "File marked as no sync, skipping sync in this cycle",
name, name,
); );
await this.registerSyncStop(); await this.registerSyncStop(false);
// Jumping out, not saving snapshot nor triggering a sync event, because we did nothing
return; return;
} }
localHash = localMeta.lastModified; localHash = localMeta.lastModified;
@ -251,15 +254,17 @@ export class SyncService {
} }
await this.spaceSync.syncFile(snapshot, name, localHash, remoteHash); await this.spaceSync.syncFile(snapshot, name, localHash, remoteHash);
this.eventHook.dispatchEvent("sync:success"); this.eventHook.dispatchEvent("sync:success").catch(console.error);
console.log("File successfully synced", name); // console.log("File successfully synced", name);
} catch (e: any) { } 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); console.error("Sync error", e);
} }
await this.saveSnapshot(snapshot); await this.saveSnapshot(snapshot);
await this.registerSyncStop(); await this.registerSyncStop(false);
console.log("And done with file sync for", name); // console.log("And done with file sync for", name);
} }
async saveSnapshot(snapshot: Map<string, SyncStatusItem>) { async saveSnapshot(snapshot: Map<string, SyncStatusItem>) {