From 16124681222aa40c3b528af7fc886394a76dc9a4 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Sun, 5 Jul 2026 10:08:20 +0000 Subject: [PATCH] Bookability: run date refresh synchronously, update timestamp immediately Backend now awaits the refresh in a thread executor instead of queuing a background task, so the response returns only after data is written. Frontend drops the 3s setTimeout and invalidates the cache immediately on success. Co-Authored-By: Claude Sonnet 4.6 --- backend/api/bookability.py | 9 +++++---- frontend/src/pages/Bookability.tsx | 7 ++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/api/bookability.py b/backend/api/bookability.py index 040d8c0..1d741f7 100644 --- a/backend/api/bookability.py +++ b/backend/api/bookability.py @@ -607,17 +607,18 @@ def _refresh_date_sync(rate_date: date): @router.post("/refresh-date/{rate_date}") async def refresh_single_date( rate_date: str, - background_tasks: BackgroundTasks, current_user: dict = Depends(get_current_user) ): """ Trigger a refresh of rates for a single date from Newbook. - Runs in background - returns immediately. + Runs synchronously so the client can invalidate its cache immediately on response. """ try: target_date = date.fromisoformat(rate_date) except ValueError: raise HTTPException(status_code=400, detail="Invalid date format. Use YYYY-MM-DD") - background_tasks.add_task(_refresh_date_sync, target_date) - return {"status": "queued", "date": rate_date, "message": f"Refreshing rates for {rate_date}"} + import asyncio + loop = asyncio.get_event_loop() + await loop.run_in_executor(None, _refresh_date_sync, target_date) + return {"status": "success", "date": rate_date, "message": f"Rates refreshed for {rate_date}"} diff --git a/frontend/src/pages/Bookability.tsx b/frontend/src/pages/Bookability.tsx index e29d1ab..3fb67cd 100644 --- a/frontend/src/pages/Bookability.tsx +++ b/frontend/src/pages/Bookability.tsx @@ -250,11 +250,8 @@ const Bookability: React.FC = () => { return res.data }, onSuccess: () => { - // Refetch after a short delay to allow background task to complete - setTimeout(() => { - queryClient.invalidateQueries({ queryKey: ['rate-matrix'] }) - setRefreshingDate(null) - }, 3000) + queryClient.invalidateQueries({ queryKey: ['rate-matrix'] }) + setRefreshingDate(null) }, onError: () => setRefreshingDate(null), })