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-05-24 - Replace blocking time.sleep with asyncio.sleep in async FastAPI routes
**Learning:** FastAPI async routes must not use blocking I/O calls like `time.sleep()`. This completely blocks the main event loop, causing the entire application to hang and fail to process other concurrent requests.
**Action:** Always use `await asyncio.sleep()` in `async def` route handlers when waiting or polling, so the event loop can process other tasks.
5 changes: 3 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 @@ -858,8 +857,10 @@ async def get_frame_image(directory_path: str, frame_index: int, project: Projec

max_wait = 30
waited = 0
# ⚑ Bolt: Use asyncio.sleep instead of time.sleep to avoid blocking the main event loop
# Impact: Allows server to handle concurrent requests while polling for frame creation
while not file_path.exists() and waited < max_wait:
time.sleep(1)
await asyncio.sleep(1)
waited += 1

if file_path.exists():
Expand Down
Loading