Repository navigation
fix(main): batch live-order database lookups to eliminate N+1 queries - #1201
Merged
Merged
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
This was referenced Oct 17, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Batch database lookups for items, tables, and bills in cloud liveOrders to eliminate N+1 queries (Issue #1187)
What Changed
CloudSyncService.liveOrderswith batchedIN (...)queries indecorateOrdersfor order items, tables, and bills.tests/cloud-live-orders-batching.test.tsto verify snapshot decoration correctness, query count bounds, timing benchmarks, and status filtering.test:cloud-live-orders-batchingscript inpackage.jsonand added it to the verification command list indocs/architecture/cloud-integrations.md.Risk Assessment
✅ Low: Batched database lookups for live orders eliminate the N+1 query loop while preserving exact snapshot schema, bill selection semantics, and PII sanitization.
Testing
Validated batched live-order database lookups by executing the dedicated regression test suite (npm run test:cloud-live-orders-batching) and standing up the real Flo POS backend against a disposable FloAdmin cloud server. Exercised 4 live end-to-end scenarios covering real WebSocket relay command dispatch with PII sanitization, elimination of N+1 database queries for 50 active orders (strictly bounded to 6 queries, 1.93ms average roundtrip), status filtering boundary guards, adversarial edge cases (multi-bill payment prioritization, dangling table resolution, empty items), and HTTP command polling fallback. All checks passed with zero findings.
Evidence: Live Validation Summary
Executive summary of live product validation for Issue #1187 / ARCH-009a.Evidence: Scenario 1: Live WebSocket Relay Orders Payload
Full JSON result frame received over WebSocket relay containing decorated orders and sanitized customer PII.Evidence: Scenario 2: N+1 Elimination Query Log & Latency Benchmark
6 queries executed for 50 orders (1.93ms average roundtrip latency).Evidence: Scenario 3: Status Filtering Boundary Responses
Order counts returned across single ('ready'), multi (['pending', 'ready']), invalid, and empty status filters.Evidence: Scenario 4: Edge Cases & HTTP Polling Fallback
Decorated edge case orders (multi-bill, null table, dangling table, empty items) and HTTP polling result.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
main/services/cloud-sync.ts:3619- Theif (itemsOverride)branch indecorateOrderduplicates single-order decoration queries and snapshot sanitization, creating a parallel copy of the decoration rule. No callers inCloudSyncServiceor the wider repository passitemsOverride, and no user intent requirement requires this parameter or fallback path. Recommend removing the unuseditemsOverrideparameter and branch, simplifyingdecorateOrder(order: any)to delegate directly tothis.decorateOrders([order])[0] ?? null.main/services/cloud-sync.ts:3641- Theif (orders.length > 200)recursive chunking branch indecorateOrdersintroduces speculative handling not required by the user intent.liveOrders()already limits queries toLIMIT 200(line 3403) anddecorateOrderpasses a single order, sodecorateOrdersnever receives more than 200 orders in normal execution. Recommend removing theif (orders.length > 200)chunking branch and its dedicated unit test intests/cloud-live-orders-batching.test.ts:378-398.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
npm run test:cloud-live-orders-batchingnode tests/run-electron-node-test.cjs tests/cloud-live-orders-batching.test.tsLive WebSocket relay orders.live command dispatch against running Flo backend with POS API order creationInstrumentation of SQLite db.prepare measuring SQL query bounds under 50 concurrent active ordersPerformance latency benchmark measuring 10 iterations of live orders retrieval (1.93ms average)Live status filtering assertion across valid, invalid, and empty status setsMulti-bill unpaid vs paid prioritization and dangling table resolution validationHTTP command polling fallback execution via /api/pos/commands✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.