fix: indexation inversée non-bloquante — run_in_executor
CI / lint (push) Failing after 7s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / security (push) Successful in 9s

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:
2026-06-04 07:33:50 -04:00
parent 7a4b3d1329
commit 8819d04cf2
3 changed files with 19 additions and 9 deletions
+5 -2
View File
@@ -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()