fix: add stats server node fallback

This commit is contained in:
2026-03-27 00:28:05 -07:00
parent d2cfa1b871
commit 8c633f7e48
4 changed files with 150 additions and 13 deletions

View File

@@ -1,9 +1,11 @@
---
id: TASK-238.5
title: Split immersion tracker query layer into focused read-model modules
status: To Do
assignee: []
status: Done
assignee:
- codex
created_date: '2026-03-26 20:49'
updated_date: '2026-03-27 00:00'
labels:
- tech-debt
- stats
@@ -29,10 +31,10 @@ priority: medium
## Acceptance Criteria
<!-- AC:BEGIN -->
- [ ] #1 Query responsibilities are grouped into focused modules such as library/session detail, vocabulary/kanji detail, and maintenance/cleanup helpers.
- [ ] #2 The stats server and immersion tracker service depend on stable exported query surfaces instead of one monolithic file.
- [ ] #3 The refactor preserves current SQL behavior and existing statistics outputs.
- [ ] #4 Existing stats/immersion tests still pass, with added focused coverage where extraction creates new seams.
- [x] #1 Query responsibilities are grouped into focused modules such as library/session detail, vocabulary/kanji detail, and maintenance/cleanup helpers.
- [x] #2 The stats server and immersion tracker service depend on stable exported query surfaces instead of one monolithic file.
- [x] #3 The refactor preserves current SQL behavior and existing statistics outputs.
- [x] #4 Existing stats/immersion tests still pass, with added focused coverage where extraction creates new seams.
<!-- AC:END -->
## Implementation Plan
@@ -43,3 +45,17 @@ priority: medium
3. Keep SQL ownership close to the domain module that consumes it; avoid a giant `queries/` dump with no structure.
4. Verify with the maintained stats/immersion test lane plus `bun run typecheck`.
<!-- SECTION:PLAN:END -->
## Implementation Notes
<!-- SECTION:NOTES:BEGIN -->
Split the monolithic query surface into focused read-model modules for sessions, trends, lexical data, library lookups, and maintenance helpers. Updated the service and test imports to use the new module boundaries.
Verification: `bun run typecheck` passed. Focused query and stats-server tests passed, including the `stats-server.test.ts` coverage around the new Bun fallback path.
<!-- SECTION:NOTES:END -->
## Final Summary
<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Extracted the immersion-tracker query layer into smaller read-model modules and kept the compatibility barrel in place so existing call sites can transition cleanly. Added focused coverage and verified the refactor with typecheck plus targeted tests.
<!-- SECTION:FINAL_SUMMARY:END -->