From 7958083fd87a06428f52b034801da70c4784bb74 Mon Sep 17 00:00:00 2001 From: bonamin Date: Mon, 1 Jun 2026 01:19:47 +0300 Subject: [PATCH] fix: push menu + stats immediately on startup instead of waiting first cycle _connect_loop now waits up to 30 seconds for the heartbeat to return site_numeric_id, then immediately pushes the menu snapshot and stats before entering the regular poll loop. Previously the first push wouldn't fire until 5 minutes after startup, making the menu unavailable until then. Co-Authored-By: Claude Sonnet 4.6 --- local_backend/services/cloud_sync.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/local_backend/services/cloud_sync.py b/local_backend/services/cloud_sync.py index 712844d..9c25367 100644 --- a/local_backend/services/cloud_sync.py +++ b/local_backend/services/cloud_sync.py @@ -446,8 +446,19 @@ async def _push_stats_snapshot(): async def _connect_loop(): """Faster loop: pulls pending online orders every CONNECT_SYNC_INTERVAL_SECONDS. - Also pushes menu snapshot and stats every 5 minutes (piggybacking on this loop).""" + Also pushes menu snapshot and stats every 5 minutes (piggybacking on this loop). + On startup, waits for the first heartbeat to populate site_numeric_id then + immediately pushes menu + stats without waiting a full cycle.""" push_every = max(1, (5 * 60) // ORDER_POLL_INTERVAL) + + # Wait for the heartbeat loop to get site_numeric_id, then do an immediate push + for _ in range(30): # wait up to 30 seconds + if license_state.get("site_numeric_id"): + break + await asyncio.sleep(1) + await _push_menu_snapshot() + await _push_stats_snapshot() + tick = 0 while True: await asyncio.sleep(ORDER_POLL_INTERVAL)