You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to PR #1201 / Issue #1187 (Cloud live-order snapshot executes N+1 database queries across active orders).
Problem
In main/services/cloud-sync.ts and attachEffectiveAddons in main/db.ts, lookups for order_items, order_item_addons, and order_audit_log generate SQL IN (?, ?, ...) clauses spanning all retrieved IDs in a single query:
constids=items.map((item)=>item.id);constplaceholders=ids.map(()=>'?').join(',');constrows=dbInstance.prepare(`SELECT * FROM order_item_addons WHERE order_item_id IN (${placeholders}) ORDER BY id`).all(...ids);
When selected orders collectively contain many items (reproduced with 164 orders with 200 items each = 32,800 items), the query attempts to bind 32,800 placeholders in a single prepared statement, exceeding SQLite's variable bind limit (SQLITE_MAX_VARIABLE_NUMBER, 32766 or legacy 999) and throwing: SqliteError: too many SQL variables
Acceptance Criteria
attachEffectiveAddons in main/db.ts and bulk lookups in main/services/cloud-sync.ts chunk large ID lists into safe bounds (e.g. <= 400 or <= 500 items per query) strictly respecting SQLite's variable limits.
Exact snapshot structure, addons attachment, audit versioning, and sanitization are preserved.
Regression test reproduces 164 orders with 200 items each without exceeding SQLite variable count or throwing errors.
Activity
fix(main): chunk order and addon queries to prevent exceeding SQLite …
khaira777 commentedon Oct 20, 2026
Verified and delivered on
mainvia PR #1224 (1bda4e7781a456ef5dbc1ffcfc6c78e2840b7537).