refactor: consolidate toDbMs into query-shared.ts

This commit is contained in:
2026-03-28 12:06:58 -07:00
parent c43941fc7e
commit 5348ae8528
5 changed files with 8 additions and 15 deletions

View File

@@ -1,9 +1,6 @@
import type { DatabaseSync } from './sqlite'; import type { DatabaseSync } from './sqlite';
import { nowMs } from './time'; import { nowMs } from './time';
import { toDbMs } from './query-shared';
function toDbMs(ms: number | bigint): bigint {
return BigInt(Math.trunc(Number(ms)));
}
const ROLLUP_STATE_KEY = 'last_rollup_sample_ms'; const ROLLUP_STATE_KEY = 'last_rollup_sample_ms';
const DAILY_MS = 86_400_000; const DAILY_MS = 86_400_000;

View File

@@ -16,6 +16,7 @@ import {
getAffectedWordIdsForSessions, getAffectedWordIdsForSessions,
getAffectedWordIdsForVideo, getAffectedWordIdsForVideo,
refreshLexicalAggregates, refreshLexicalAggregates,
toDbMs,
} from './query-shared'; } from './query-shared';
type CleanupVocabularyRow = { type CleanupVocabularyRow = {
@@ -543,6 +544,3 @@ export function deleteVideo(db: DatabaseSync, videoId: number): void {
throw error; throw error;
} }
} }
function toDbMs(ms: number | bigint): bigint {
return BigInt(Math.trunc(Number(ms)));
}

View File

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

View File

@@ -4,10 +4,7 @@ import { createInitialSessionState } from './reducer';
import { nowMs } from './time'; import { nowMs } from './time';
import { SESSION_STATUS_ACTIVE, SESSION_STATUS_ENDED } from './types'; import { SESSION_STATUS_ACTIVE, SESSION_STATUS_ENDED } from './types';
import type { SessionState } from './types'; import type { SessionState } from './types';
import { toDbMs } from './query-shared';
function toDbMs(ms: number | bigint): bigint {
return BigInt(Math.trunc(Number(ms)));
}
export function startSessionRecord( export function startSessionRecord(
db: DatabaseSync, db: DatabaseSync,

View File

@@ -4,10 +4,7 @@ import type { DatabaseSync } from './sqlite';
import { nowMs } from './time'; import { nowMs } from './time';
import { SCHEMA_VERSION } from './types'; import { SCHEMA_VERSION } from './types';
import type { QueuedWrite, VideoMetadata, YoutubeVideoMetadata } from './types'; import type { QueuedWrite, VideoMetadata, YoutubeVideoMetadata } from './types';
import { toDbMs } from './query-shared';
function toDbMs(ms: number | bigint): bigint {
return BigInt(Math.trunc(Number(ms)));
}
export interface TrackerPreparedStatements { export interface TrackerPreparedStatements {
telemetryInsertStmt: ReturnType<DatabaseSync['prepare']>; telemetryInsertStmt: ReturnType<DatabaseSync['prepare']>;