From 6ddb533fe65bce9642344abfda3f8215a633630d Mon Sep 17 00:00:00 2001 From: Gamosoft Date: Tue, 30 Jun 2026 16:02:44 +0200 Subject: [PATCH] warm up --- backend/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/main.py b/backend/main.py index 5417fb6..9a41d38 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1823,6 +1823,26 @@ app.include_router(api_router) app.include_router(pages_router) +# ============================================================================ +# Startup warmup +# ============================================================================ +# Pre-build the note index in a daemon thread so the first /api/notes request +# hits a warm index. Concurrent requests landing mid-warmup are safe: bulk_set +# is serialized by the index RLock and short-circuits via the fingerprint hash. +@app.on_event("startup") +def _warmup_note_index() -> None: + import threading + + def _build() -> None: + try: + ensure_index_built(config['storage']['notes_dir']) + print("✅ Note index warmed up") + except Exception as exc: + print(f"⚠️ Note index warmup failed (will build on first request): {exc}") + + threading.Thread(target=_build, name="note-index-warmup", daemon=True).start() + + if __name__ == "__main__": import uvicorn uvicorn.run(