fix: indexation inversée non-bloquante — run_in_executor
L'étape 'Building inverted index...' au démarrage bloquait l'event loop asyncio, empêchant le serveur de répondre aux requêtes HTTP (navigation, refresh) jusqu'à la fin de l'indexation. - init_inverted_index() exécuté dans ThreadPoolExecutor via run_in_executor - get_inverted_index() ne fait plus de rebuild auto bloquant - Le serveur répond immédiatement, même pendant l'indexation
This commit is contained in:
+5
-2
@@ -573,8 +573,11 @@ async def lifespan(app: FastAPI):
|
||||
logger.info("Background indexing started")
|
||||
await build_index(_progress_cb)
|
||||
|
||||
# Build inverted index for search (one-time, then incremental)
|
||||
init_inverted_index()
|
||||
# Build inverted index in a thread pool to avoid blocking the event loop.
|
||||
# The inverted index rebuild is CPU-bound (tokenization, indexing) and
|
||||
# would freeze HTTP responses if run in the async event loop.
|
||||
loop = asyncio.get_running_loop()
|
||||
await loop.run_in_executor(_search_executor, init_inverted_index)
|
||||
|
||||
# Start file watcher
|
||||
config = _load_config()
|
||||
|
||||
Reference in New Issue
Block a user