From d4b68154df047565be089e4c9936a13a01463199 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 22 Nov 2025 20:31:27 +0000 Subject: [PATCH] Export consts --- frontend/sync-client/src/consts.ts | 6 ++++++ frontend/sync-client/src/services/sync-service.ts | 6 +++--- frontend/sync-client/src/tracing/logger.ts | 5 +++-- frontend/sync-client/src/tracing/sync-history.ts | 11 ++++++----- 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 frontend/sync-client/src/consts.ts diff --git a/frontend/sync-client/src/consts.ts b/frontend/sync-client/src/consts.ts new file mode 100644 index 00000000..5eafa3aa --- /dev/null +++ b/frontend/sync-client/src/consts.ts @@ -0,0 +1,6 @@ +export const NETWORK_RETRY_INTERVAL_MS = 1000; +export const MINIMUM_SAVE_INTERVAL_MS = 1000; +export const DIFF_CACHE_SIZE_MB = 2; +export const MAX_LOG_MESSAGE_COUNT = 100000; +export const MAX_HISTORY_ENTRY_COUNT = 5000; +export const TIMEOUT_FOR_MERGING_HISTORY_ENTRIES_IN_SECONDS = 60; diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index af3543da..331f806c 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -17,6 +17,7 @@ import type { FetchLatestDocumentsResponse } from "./types/FetchLatestDocumentsR import type { PingResponse } from "./types/PingResponse"; import type { DeleteDocumentVersion } from "./types/DeleteDocumentVersion"; import type { UpdateTextDocumentVersion } from "./types/UpdateTextDocumentVersion"; +import { NETWORK_RETRY_INTERVAL_MS } from "../consts"; export interface CheckConnectionResult { isSuccessful: boolean; @@ -24,7 +25,6 @@ export interface CheckConnectionResult { } export class SyncService { - private static readonly NETWORK_RETRY_INTERVAL_MS = 1000; private readonly client: typeof globalThis.fetch; private readonly pingClient: typeof globalThis.fetch; @@ -374,9 +374,9 @@ export class SyncService { } this.logger.error( - `Failed network call (${e}), retrying in ${SyncService.NETWORK_RETRY_INTERVAL_MS}ms` + `Failed network call (${e}), retrying in ${NETWORK_RETRY_INTERVAL_MS}ms` ); - await sleep(SyncService.NETWORK_RETRY_INTERVAL_MS); + await sleep(NETWORK_RETRY_INTERVAL_MS); } } } diff --git a/frontend/sync-client/src/tracing/logger.ts b/frontend/sync-client/src/tracing/logger.ts index cf39e4de..ca32bbce 100644 --- a/frontend/sync-client/src/tracing/logger.ts +++ b/frontend/sync-client/src/tracing/logger.ts @@ -1,3 +1,5 @@ +import { MAX_LOG_MESSAGE_COUNT } from "../consts"; + export enum LogLevel { DEBUG = "DEBUG", INFO = "INFO", @@ -21,7 +23,6 @@ export class LogLine { } export class Logger { - private static readonly MAX_MESSAGES = 100000; private readonly messages: LogLine[] = []; private readonly onMessageListeners: ((message: LogLine) => unknown)[] = []; @@ -68,7 +69,7 @@ export class Logger { const logLine = new LogLine(level, message); this.messages.push(logLine); - while (this.messages.length > Logger.MAX_MESSAGES) { + while (this.messages.length > MAX_LOG_MESSAGE_COUNT) { this.messages.shift(); } diff --git a/frontend/sync-client/src/tracing/sync-history.ts b/frontend/sync-client/src/tracing/sync-history.ts index 92904ce6..915c78b7 100644 --- a/frontend/sync-client/src/tracing/sync-history.ts +++ b/frontend/sync-client/src/tracing/sync-history.ts @@ -1,3 +1,7 @@ +import { + MAX_HISTORY_ENTRY_COUNT, + TIMEOUT_FOR_MERGING_HISTORY_ENTRIES_IN_SECONDS +} from "../consts"; import type { RelativePath } from "../persistence/database"; import type { Logger } from "./logger"; @@ -64,9 +68,6 @@ export interface HistoryStats { } export class SyncHistory { - private static readonly MAX_ENTRIES = 5000; - private static readonly TIMEOUT_FOR_MERGING_ENTRIES_IN_SECONDS = 60; - private _entries: HistoryEntry[] = []; private readonly syncHistoryUpdateListeners: (( @@ -104,7 +105,7 @@ export class SyncHistory { // Insert the entry at the beginning this._entries.unshift(historyEntry); - if (this._entries.length > SyncHistory.MAX_ENTRIES) { + if (this._entries.length > MAX_HISTORY_ENTRY_COUNT) { this._entries.pop(); } @@ -145,7 +146,7 @@ export class SyncHistory { candidate !== undefined && (this._entries[0] === candidate || candidate.timestamp.getTime() + - SyncHistory.TIMEOUT_FOR_MERGING_ENTRIES_IN_SECONDS * 1000 > + TIMEOUT_FOR_MERGING_HISTORY_ENTRIES_IN_SECONDS * 1000 > entry.timestamp.getTime()) ) { return candidate;