diff --git a/src/core/services/immersion-tracker/maintenance.ts b/src/core/services/immersion-tracker/maintenance.ts index a20fc77..3c4034d 100644 --- a/src/core/services/immersion-tracker/maintenance.ts +++ b/src/core/services/immersion-tracker/maintenance.ts @@ -1,9 +1,6 @@ import type { DatabaseSync } from './sqlite'; import { nowMs } from './time'; - -function toDbMs(ms: number | bigint): bigint { - return BigInt(Math.trunc(Number(ms))); -} +import { toDbMs } from './query-shared'; const ROLLUP_STATE_KEY = 'last_rollup_sample_ms'; const DAILY_MS = 86_400_000; diff --git a/src/core/services/immersion-tracker/query-maintenance.ts b/src/core/services/immersion-tracker/query-maintenance.ts index 420c69d..022386f 100644 --- a/src/core/services/immersion-tracker/query-maintenance.ts +++ b/src/core/services/immersion-tracker/query-maintenance.ts @@ -16,6 +16,7 @@ import { getAffectedWordIdsForSessions, getAffectedWordIdsForVideo, refreshLexicalAggregates, + toDbMs, } from './query-shared'; type CleanupVocabularyRow = { @@ -543,6 +544,3 @@ export function deleteVideo(db: DatabaseSync, videoId: number): void { throw error; } } -function toDbMs(ms: number | bigint): bigint { - return BigInt(Math.trunc(Number(ms))); -} diff --git a/src/core/services/immersion-tracker/query-shared.ts b/src/core/services/immersion-tracker/query-shared.ts index adab3d5..ffd59a5 100644 --- a/src/core/services/immersion-tracker/query-shared.ts +++ b/src/core/services/immersion-tracker/query-shared.ts @@ -270,3 +270,7 @@ export function deleteSessionsByIds(db: DatabaseSync, sessionIds: number[]): voi ); db.prepare(`DELETE FROM imm_sessions WHERE session_id IN (${placeholders})`).run(...sessionIds); } + +export function toDbMs(ms: number | bigint): bigint { + return BigInt(Math.trunc(Number(ms))); +} diff --git a/src/core/services/immersion-tracker/session.ts b/src/core/services/immersion-tracker/session.ts index e3f89e1..b0484f6 100644 --- a/src/core/services/immersion-tracker/session.ts +++ b/src/core/services/immersion-tracker/session.ts @@ -4,10 +4,7 @@ import { createInitialSessionState } from './reducer'; import { nowMs } from './time'; import { SESSION_STATUS_ACTIVE, SESSION_STATUS_ENDED } from './types'; import type { SessionState } from './types'; - -function toDbMs(ms: number | bigint): bigint { - return BigInt(Math.trunc(Number(ms))); -} +import { toDbMs } from './query-shared'; export function startSessionRecord( db: DatabaseSync, diff --git a/src/core/services/immersion-tracker/storage.ts b/src/core/services/immersion-tracker/storage.ts index 3fa4174..ce8833c 100644 --- a/src/core/services/immersion-tracker/storage.ts +++ b/src/core/services/immersion-tracker/storage.ts @@ -4,10 +4,7 @@ import type { DatabaseSync } from './sqlite'; import { nowMs } from './time'; import { SCHEMA_VERSION } from './types'; import type { QueuedWrite, VideoMetadata, YoutubeVideoMetadata } from './types'; - -function toDbMs(ms: number | bigint): bigint { - return BigInt(Math.trunc(Number(ms))); -} +import { toDbMs } from './query-shared'; export interface TrackerPreparedStatements { telemetryInsertStmt: ReturnType;