From ef5d3daf4cc6db1c829c238f90d2f6461659b620 Mon Sep 17 00:00:00 2001 From: altair823 Date: Tue, 5 May 2026 00:11:38 +0900 Subject: [PATCH] =?UTF-8?q?refactor(v024):=20TelemetryService=20DAY=5FMS?= =?UTF-8?q?=20=EC=83=81=EC=88=98=20+=20media.gc=20.catch=20(backlog=20#2?= =?UTF-8?q?=20#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #2: 24*60*60*1000 magic number → 모듈 상단 const DAY_MS cleanupOldFiles + readAllRecent 두 callsite 통일 - #6: gc.run() 의 .catch 누락 → backup.runDaily 패턴 통일 실패 시 logger.warn('media.gc.failed', { reason }) Note: backlog #1 (now() 2번 호출) 은 PR #13 round 1 review 시 이미 fix — backlog 항목 stale. v0.2.5 brainstorm 시 backlog 정리. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/main/index.ts | 4 +++- src/main/services/TelemetryService.ts | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index f4f3932..d102550 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -146,7 +146,9 @@ app.whenReady().then(async () => { await worker.loadFromDb(); const gc = new MediaGc(db, store); - void gc.run().then((r) => logger.info('media.gc', { ...r } as Record)); + void gc.run() + .then((r) => logger.info('media.gc', { ...r } as Record)) + .catch((e) => logger.warn('media.gc.failed', { reason: String(e) })); const exportSvc = new ExportService(repo, store); const importSvc = new ImportService(repo, store); diff --git a/src/main/services/TelemetryService.ts b/src/main/services/TelemetryService.ts index cb5e0c6..fe7abd1 100644 --- a/src/main/services/TelemetryService.ts +++ b/src/main/services/TelemetryService.ts @@ -4,6 +4,7 @@ import { validateEvent, TelemetryEvent } from './telemetryEvents.js'; import { aggregateStats } from './telemetryStats.js'; const KST_OFFSET_MS = 9 * 60 * 60 * 1000; +const DAY_MS = 24 * 60 * 60 * 1000; function todayKstIso(now: Date): string { const k = new Date(now.getTime() + KST_OFFSET_MS); @@ -52,7 +53,7 @@ export class TelemetryService { } catch { return { removed }; } - const cutoff = new Date(this.now().getTime() - this.retentionDays * 24 * 60 * 60 * 1000); + const cutoff = new Date(this.now().getTime() - this.retentionDays * DAY_MS); const cutoffIso = todayKstIso(cutoff); // KST 일자 비교 for (const name of entries) { const m = /^events-(\d{4}-\d{2}-\d{2})\.jsonl$/.exec(name); @@ -94,7 +95,7 @@ export class TelemetryService { } catch { return events; } - const cutoffMs = this.now().getTime() - this.retentionDays * 24 * 60 * 60 * 1000; + const cutoffMs = this.now().getTime() - this.retentionDays * DAY_MS; const cutoffIso = todayKstIso(new Date(cutoffMs)); // 회차 1 review (PR #13) — 매직 슬라이스 `n.slice(7, 17)` 대신 정규식 capture 그룹으로 // 일자를 추출. prefix 변경 시 정규식 한 곳만 고치면 됨.