Skip to content

fix(kds): reduce polling, reconnect, and database overhead - #323

Merged
khaira777 merged 2 commits into
mainfrom
fix/226-kds-perf
Aug 16, 2026
Merged

fix(kds): reduce polling, reconnect, and database overhead#323
khaira777 merged 2 commits into
mainfrom
fix/226-kds-perf

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Reduce FloCafe KDS polling, reconnect, and database overhead: batch the standalone poll item and addon queries, dedupe the global voided-item expiry marker query, bound WebSocket reconnect attempts with exponential backoff, isolate the elapsed-time clock tick, and add query-count regression coverage

What Changed

  • Batched standalone KDS order item queries into a single IN (...) lookup and deduped global voided-item expiry marker queries across clients during heartbeat ticks and broadcasts.
  • Implemented bounded exponential backoff (1s–30s) for KDS WebSocket reconnection attempts.
  • Isolated the live elapsed-time timer into a dedicated ElapsedTime component to eliminate 1-second full-board re-renders in Kanban and tabs views, and added query-count regression test coverage.

Risk Assessment

✅ Low: The changes cleanly optimize KDS database queries, WebSocket reconnection backoff, and React component rendering without altering functional behavior or breaking existing invariants.

Testing

Executed targeted KDS test suites, Playwright E2E browser interactions, query-count regression checks, and performance verification scripts. Verified batched polling item queries (1 batched query vs N sequential queries), single global void marker computation across all connected clients, 1s-30s bounded exponential backoff on WebSocket reconnection, and clock tick isolation via the dedicated ElapsedTime component. All 12 automated test suites passed and captured UI screenshot evidence for both Kanban and Tabs views.

  • Evidence: KDS Kanban Board with Isolated Elapsed-Time Clock (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M04HC60QE719ZEWJP17HEP8P/kds-kanban-view.png)
  • Evidence: KDS Tabs View with Isolated Elapsed-Time Clock (local file: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M04HC60QE719ZEWJP17HEP8P/kds-tabs-view.png)
Evidence: KDS Performance Optimization Verification Log

FloCafe KDS Optimization & Query Overhead Verification (Issue #226) --- VERIFICATION 1: Batched Standalone Poll Item & Addon Queries --- ✓ Total queries executed during /api/kds/orders poll for 5 orders: 12 ✓ Batched item queries executed: 1 (Expected: 1) ✓ Unbatched single-order item queries: 0 (Expected: 0) ✓ PASS: Standalone poll items and addons are batched into a single query pass across all active orders. --- VERIFICATION 2: Deduplicated Global Voided-Item Expiry Marker Query --- ✓ Heartbeat computes getExpiredVoidMarker() once globally per tick: true ✓ Broadcast computes getExpiredVoidMarker() once globally per broadcast: true ✓ PASS: Global voided-item expiry marker query is deduplicated across all connected WebSocket clients. --- VERIFICATION 3: Bounded WebSocket Reconnect Exponential Backoff --- Attempt 0: delay = 1000ms (expected: 1000ms) Attempt 1: delay = 2000ms (expected: 2000ms) Attempt 2: delay = 4000ms (expected: 4000ms) Attempt 3: delay = 8000ms (expected: 8000ms) Attempt 4: delay = 16000ms (expected: 16000ms) Attempt 5: delay = 30000ms (expected: 30000ms) Attempt 6: delay = 30000ms (expected: 30000ms) Attempt 10: delay = 30000ms (expected: 30000ms) ✓ PASS: WebSocket reconnect uses bounded exponential backoff (1s -> 30s max cap). --- VERIFICATION 4: Elapsed-Time Clock Tick Component Isolation --- ✓ KdsKanbanBoard root setClockTick removed: true ✓ KdsTabsView root setClockTick removed: true ✓ ElapsedTime component encapsulates isolated 1-second interval: true ✓ PASS: Elapsed-time clock ticks are isolated to individual card sub-components, preventing whole-board re-renders. ALL KDS PERFORMANCE OPTIMIZATION CHECKS VERIFIED SUCCESSFULLY!

======================================================================
FloCafe KDS Optimization & Query Overhead Verification (Issue #226)
======================================================================

[1] Database initialized. Seeding test users and catalog...
[2] Seeding 5 active orders with items and addons to test batch polling...
[3] KDS Server running on port 3005

--- VERIFICATION 1: Batched Standalone Poll Item & Addon Queries ---
✓ Total queries executed during /api/kds/orders poll for 5 orders: 12
✓ Batched item queries executed: 1 (Expected: 1)
✓ Unbatched single-order item queries: 0 (Expected: 0)
✓ PASS: Standalone poll items and addons are batched into a single query pass across all active orders.

--- VERIFICATION 2: Deduplicated Global Voided-Item Expiry Marker Query ---
✓ Heartbeat computes getExpiredVoidMarker() once globally per tick: true
✓ Broadcast computes getExpiredVoidMarker() once globally per broadcast: true
✓ PASS: Global voided-item expiry marker query is deduplicated across all connected WebSocket clients.

--- VERIFICATION 3: Bounded WebSocket Reconnect Exponential Backoff ---
  Attempt 0: delay = 1000ms (expected: 1000ms)
  Attempt 1: delay = 2000ms (expected: 2000ms)
  Attempt 2: delay = 4000ms (expected: 4000ms)
  Attempt 3: delay = 8000ms (expected: 8000ms)
  Attempt 4: delay = 16000ms (expected: 16000ms)
  Attempt 5: delay = 30000ms (expected: 30000ms)
  Attempt 6: delay = 30000ms (expected: 30000ms)
  Attempt 10: delay = 30000ms (expected: 30000ms)
✓ PASS: WebSocket reconnect uses bounded exponential backoff (1s -> 30s max cap).

--- VERIFICATION 4: Elapsed-Time Clock Tick Component Isolation ---
✓ KdsKanbanBoard root setClockTick removed: true
✓ KdsTabsView root setClockTick removed: true
✓ ElapsedTime component encapsulates isolated 1-second interval: true
✓ PASS: Elapsed-time clock ticks are isolated to individual card sub-components, preventing whole-board re-renders.

======================================================================
ALL KDS PERFORMANCE OPTIMIZATION CHECKS VERIFIED SUCCESSFULLY!
======================================================================

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • npm run test:kds-integration
  • npm run test:kds-contract
  • npm run test:kds-frontend-conflict
  • npm run test:kds-window-hardening
  • node tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.ts
  • node tests/run-electron-node-test.cjs tests/kitchen-addons-parsing.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-125-addon-read-paths.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-133-kds-kot-toggles.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-134-station-routing.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-134-station-management.test.ts
  • npx playwright test e2e/kds-kanban-skip-confirm.spec.ts
  • node tests/run-electron-node-test.cjs verify-kds-perf.cjs
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

- Batch the standalone poll's per-order item and addon queries into single queries
- Compute the global voided-item expiry marker once per broadcast and heartbeat
- Use bounded exponential backoff for WebSocket reconnects
- Isolate the 1s elapsed-time tick so the board/tabs don't rescan every second
- Add a query-count regression check for the standalone poll

Closes #226
@khaira777
khaira777 requested a review from itsbkm as a code owner August 16, 2026 05:46
@khaira777
khaira777 merged commit 9b0831f into main Aug 16, 2026
9 checks passed
@khaira777
khaira777 deleted the fix/226-kds-perf branch August 16, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant