Replace misleading Promise.all with sequential sync calls#400
Conversation
better-sqlite3 is synchronous — Promise.all provided no parallelism, only false suggestion of concurrency. Closes #201 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR refactors query execution in the schedules router from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/server/routers/schedules.ts (1)
50-64: Correctly addresses the misleadingPromise.allpattern.The refactor properly replaces
Promise.allwith sequential.all()calls, accurately reflecting that better-sqlite3 queries execute synchronously. The code is functionally equivalent and more honest about the actual execution model.However,
src/server/routers/health.ts(lines 149-165) still usesawait Promise.all([...])for fetching the same three schedule types. For codebase consistency, consider applying the same refactor there.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/server/routers/schedules.ts` around lines 50 - 64, The health router still uses await Promise.all([...]) to fetch schedule rows even though better-sqlite3 queries are synchronous; update the health handler to mirror the change in schedules.ts by replacing the Promise.all call with three synchronous queries that call .select().from(...).where(eq(..., input.side)).all() and assign them to temperatureSchedulesList, powerSchedulesList, and alarmSchedulesList (or the local variable names used in that file) so the code is consistent and avoids the misleading async pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/server/routers/schedules.ts`:
- Around line 50-64: The health router still uses await Promise.all([...]) to
fetch schedule rows even though better-sqlite3 queries are synchronous; update
the health handler to mirror the change in schedules.ts by replacing the
Promise.all call with three synchronous queries that call
.select().from(...).where(eq(..., input.side)).all() and assign them to
temperatureSchedulesList, powerSchedulesList, and alarmSchedulesList (or the
local variable names used in that file) so the code is consistent and avoids the
misleading async pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 761b468f-e095-49a7-9ad7-b1bb89dfd650
📒 Files selected for processing (1)
src/server/routers/schedules.ts
- Replace misleading Promise.all with sequential .all() calls in health router drift detection (matches schedules.ts pattern from #400) - Replace z.any() with concrete Zod output schema for settings getAll endpoint to prevent missing-field regressions like #401 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary - Replace misleading `Promise.all` with sequential `.all()` calls in health router drift detection — mirrors the fix applied to schedules.ts in #400 - Replace `z.any()` with concrete Zod output schema for settings `getAll` endpoint — prevents missing-field regressions like the one fixed in #401 ## Test plan - [x] TypeScript compiles clean (`tsc --noEmit`) - [x] Lint passes (pre-commit hook) - [ ] Verify `/health/system` endpoint returns drift detection data correctly - [ ] Verify `/settings` endpoint returns full settings payload without validation errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Reorganized health monitoring detection to execute database queries sequentially, improving monitoring consistency. * **Chores** * Added stricter validation schemas for settings API responses to ensure type safety and consistency across device settings, gesture controls, and side-specific configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🎉 This PR is included in version 1.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Promise.allwrapping synchronous better-sqlite3/drizzle queries with sequential.all()calls ingetAllandgetByDayhandlersPromise.allprovided no parallelism, only a false suggestion of concurrencyCloses #201
Test plan
getAllandgetByDayendpoints return correct data🤖 Generated with Claude Code
Summary by CodeRabbit