Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
## 2024-06-28 - Optimize array lookups in high-frequency React event handlers
**Learning:** Even if data is pre-processed/memoized (like cached `parsedTimestamps`), performing an O(N) linear search on that array inside a high-frequency event handler (like `<video onTimeUpdate>`, which fires multiple times per second) can cause UI stuttering for large arrays.
**Action:** When searching sorted arrays (like ordered video timestamps) in high-frequency event loops, replace linear iteration loops with an O(log N) binary search to minimize main thread blocking and ensure smooth UI execution.

## 2024-06-30 - Avoid blocking the event loop in FastAPI routes
**Learning:** Using synchronous `time.sleep()` inside an `async def` route in FastAPI blocks the entire event loop. A single slow request waiting for an operation (like `get_frame_image` waiting for a file) will freeze the entire backend and prevent any other concurrent requests from being processed.
**Action:** Always use `await asyncio.sleep()` for waiting inside `async def` endpoints so the event loop can yield control and process other requests concurrently.
4 changes: 2 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import List, Dict, Any
from pydantic import BaseModel, Field
from pathlib import Path
import time

from scanner import scan_directory_for_videos
from extractor import async_extract_keyframes_parallel, async_get_video_duration
Expand Down Expand Up @@ -859,7 +858,8 @@ async def get_frame_image(directory_path: str, frame_index: int, project: Projec
max_wait = 30
waited = 0
while not file_path.exists() and waited < max_wait:
time.sleep(1)
# ⚑ Bolt: Use asyncio.sleep to prevent blocking the entire FastAPI event loop
await asyncio.sleep(1)
waited += 1

if file_path.exists():
Expand Down
Loading