Export consts

This commit is contained in:
Andras Schmelczer 2025-11-22 20:31:27 +00:00
parent c798d96009
commit d4b68154df
4 changed files with 18 additions and 10 deletions

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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();
}

View file

@ -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;