Export consts
This commit is contained in:
parent
c798d96009
commit
d4b68154df
4 changed files with 18 additions and 10 deletions
6
frontend/sync-client/src/consts.ts
Normal file
6
frontend/sync-client/src/consts.ts
Normal 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;
|
||||||
|
|
@ -17,6 +17,7 @@ import type { FetchLatestDocumentsResponse } from "./types/FetchLatestDocumentsR
|
||||||
import type { PingResponse } from "./types/PingResponse";
|
import type { PingResponse } from "./types/PingResponse";
|
||||||
import type { DeleteDocumentVersion } from "./types/DeleteDocumentVersion";
|
import type { DeleteDocumentVersion } from "./types/DeleteDocumentVersion";
|
||||||
import type { UpdateTextDocumentVersion } from "./types/UpdateTextDocumentVersion";
|
import type { UpdateTextDocumentVersion } from "./types/UpdateTextDocumentVersion";
|
||||||
|
import { NETWORK_RETRY_INTERVAL_MS } from "../consts";
|
||||||
|
|
||||||
export interface CheckConnectionResult {
|
export interface CheckConnectionResult {
|
||||||
isSuccessful: boolean;
|
isSuccessful: boolean;
|
||||||
|
|
@ -24,7 +25,6 @@ export interface CheckConnectionResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SyncService {
|
export class SyncService {
|
||||||
private static readonly NETWORK_RETRY_INTERVAL_MS = 1000;
|
|
||||||
private readonly client: typeof globalThis.fetch;
|
private readonly client: typeof globalThis.fetch;
|
||||||
private readonly pingClient: typeof globalThis.fetch;
|
private readonly pingClient: typeof globalThis.fetch;
|
||||||
|
|
||||||
|
|
@ -374,9 +374,9 @@ export class SyncService {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.error(
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { MAX_LOG_MESSAGE_COUNT } from "../consts";
|
||||||
|
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
DEBUG = "DEBUG",
|
DEBUG = "DEBUG",
|
||||||
INFO = "INFO",
|
INFO = "INFO",
|
||||||
|
|
@ -21,7 +23,6 @@ export class LogLine {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Logger {
|
export class Logger {
|
||||||
private static readonly MAX_MESSAGES = 100000;
|
|
||||||
private readonly messages: LogLine[] = [];
|
private readonly messages: LogLine[] = [];
|
||||||
private readonly onMessageListeners: ((message: LogLine) => unknown)[] = [];
|
private readonly onMessageListeners: ((message: LogLine) => unknown)[] = [];
|
||||||
|
|
||||||
|
|
@ -68,7 +69,7 @@ export class Logger {
|
||||||
const logLine = new LogLine(level, message);
|
const logLine = new LogLine(level, message);
|
||||||
this.messages.push(logLine);
|
this.messages.push(logLine);
|
||||||
|
|
||||||
while (this.messages.length > Logger.MAX_MESSAGES) {
|
while (this.messages.length > MAX_LOG_MESSAGE_COUNT) {
|
||||||
this.messages.shift();
|
this.messages.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 { RelativePath } from "../persistence/database";
|
||||||
import type { Logger } from "./logger";
|
import type { Logger } from "./logger";
|
||||||
|
|
||||||
|
|
@ -64,9 +68,6 @@ export interface HistoryStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SyncHistory {
|
export class SyncHistory {
|
||||||
private static readonly MAX_ENTRIES = 5000;
|
|
||||||
private static readonly TIMEOUT_FOR_MERGING_ENTRIES_IN_SECONDS = 60;
|
|
||||||
|
|
||||||
private _entries: HistoryEntry[] = [];
|
private _entries: HistoryEntry[] = [];
|
||||||
|
|
||||||
private readonly syncHistoryUpdateListeners: ((
|
private readonly syncHistoryUpdateListeners: ((
|
||||||
|
|
@ -104,7 +105,7 @@ export class SyncHistory {
|
||||||
// Insert the entry at the beginning
|
// Insert the entry at the beginning
|
||||||
this._entries.unshift(historyEntry);
|
this._entries.unshift(historyEntry);
|
||||||
|
|
||||||
if (this._entries.length > SyncHistory.MAX_ENTRIES) {
|
if (this._entries.length > MAX_HISTORY_ENTRY_COUNT) {
|
||||||
this._entries.pop();
|
this._entries.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +146,7 @@ export class SyncHistory {
|
||||||
candidate !== undefined &&
|
candidate !== undefined &&
|
||||||
(this._entries[0] === candidate ||
|
(this._entries[0] === candidate ||
|
||||||
candidate.timestamp.getTime() +
|
candidate.timestamp.getTime() +
|
||||||
SyncHistory.TIMEOUT_FOR_MERGING_ENTRIES_IN_SECONDS * 1000 >
|
TIMEOUT_FOR_MERGING_HISTORY_ENTRIES_IN_SECONDS * 1000 >
|
||||||
entry.timestamp.getTime())
|
entry.timestamp.getTime())
|
||||||
) {
|
) {
|
||||||
return candidate;
|
return candidate;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue