managarten/services
Till JS 8fd9b7da79 perf(mana-ai): materialize mission snapshots, drop per-tick full replay
Replaces the O(N sync_changes) LWW replay in every tick with an
incremental snapshot table refresh. Each tick now applies only the
delta since the last run, then runs a single indexed SELECT on the
snapshot table to find due missions.

- `db/migrate.ts` — idempotent migration. Creates `mana_ai` schema and
  `mana_ai.mission_snapshots` table on boot. Partial index on
  active+nextRunAt powers the tick's "due" query.
- `db/snapshot-refresh.ts`
  - `refreshSnapshots(sql)` one-pass: joins sync_changes and snapshots
    on (user_id, mission_id), picks out pairs whose source max
    created_at exceeds the snapshot cursor. Per-pair refresh wrapped
    in `withUser` for RLS scoping on the source SELECT.
  - Bootstrap: missing snapshot rows seed from a full replay of their
    mission's history; subsequent ticks apply only the delta.
  - Delete tombstones purge the snapshot row.
- `db/missions-projection.ts` `listDueMissions` — single SELECT against
  `mana_ai.mission_snapshots` with an indexed WHERE. Dropped the legacy
  cross-user scan + per-user two-phase read (unused now). `mergeAndFilter`
  stays for its existing test coverage.
- `cron/tick.ts` calls `refreshSnapshots` before `listDueMissions` and
  logs when the refresh actually applied rows. No behaviour change
  externally.
- `index.ts` awaits `migrate()` on boot (top-level `await` — Bun
  supports it natively).

Closes the last item on the AI-Workbench roadmap's "future work" list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 01:28:24 +02:00
..
mana-ai perf(mana-ai): materialize mission snapshots, drop per-tick full replay 2026-04-15 01:28:24 +02:00
mana-analytics refactor(shared-tailwind): rewrite themes.css to single-layer shadcn convention 2026-04-09 01:13:06 +02:00
mana-api-gateway chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
mana-auth refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
mana-crawler chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
mana-credits feat(credits): admin-gifted sync subscriptions 2026-04-14 14:11:07 +02:00
mana-events docs(services): add CLAUDE.md for stt + events, fix stale entries, flag port collisions 2026-04-08 12:23:48 +02:00
mana-geocoding test(geocoding): add unit tests + end-to-end smoke test script 2026-04-11 20:21:18 +02:00
mana-image-gen feat(mana-image-gen): replace Mac flux2.c implementation with Windows GPU diffusers 2026-04-08 13:02:42 +02:00
mana-landing-builder chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
mana-llm fix(mana-llm): add response_format to ChatCompletionRequest model 2026-04-09 18:50:54 +02:00
mana-mail feat(mail): add mana-mail service and frontend module (Phase 1 MVP) 2026-04-13 20:35:54 +02:00
mana-media refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
mana-notify fix(mana-auth) + chore: rewrite /api/v1/auth/login JWT mint, remove Matrix stack 2026-04-08 16:32:13 +02:00
mana-search fix: dev startup — Redis eviction policy, mana-media port crash, Svelte warnings 2026-04-10 18:33:41 +02:00
mana-stt chore(mac-mini): remove all AI service infrastructure (moved to Windows GPU) 2026-04-08 13:06:40 +02:00
mana-subscriptions refactor: rename planta → plants, clean up codebase 2026-04-12 18:59:44 +02:00
mana-sync docs(ai): mark Step 8 (mana-sync actor field) done; document sync_changes.actor 2026-04-14 23:37:55 +02:00
mana-tts chore(mac-mini): remove all AI service infrastructure (moved to Windows GPU) 2026-04-08 13:06:40 +02:00
mana-user refactor(shared-tailwind): rewrite themes.css to single-layer shadcn convention 2026-04-09 01:13:06 +02:00
mana-video-gen chore(matrix): final scrub of stale matrix references 2026-04-08 16:47:54 +02:00
mana-voice-bot fix(mana-voice-bot): move default port 3050 → 3024 + Windows GPU deployment notes 2026-04-08 13:14:57 +02:00
news-ingester fix(news-ingester): disable Readability fallback to break crash loop 2026-04-09 16:21:09 +02:00