From 58945bf95a3d54f0df62e7a15f9b9d4ae0f5f9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Thu, 25 Sep 2025 22:05:41 +0200 Subject: [PATCH 1/2] build: add local db file to make file --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36a17f6..2deeeb4 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ test: pytest dev: - fastapi dev app.py --host 0.0.0.0 + MUSICLIBRARY_DB=musiclibrary.db fastapi dev app.py --host 0.0.0.0 prod: fastapi run app.py From 11c581abc08b9504890c3f02968b379f27128b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Gilli=C3=9Fen?= Date: Thu, 25 Sep 2025 22:09:32 +0200 Subject: [PATCH 2/2] feat: add a slow log warning on slow queries --- app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app.py b/app.py index e23b816..027550e 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ import logging +import time from typing import Annotated from urllib.parse import quote_plus @@ -18,6 +19,7 @@ console_handler = logging.StreamHandler() console_handler.setFormatter(Logfmter(keys=["at", "name", "asctime"])) logging.basicConfig(level=logging.INFO, handlers=[console_handler]) +SLOW_REQUEST_THRESHOLD = 500 logger = logging.getLogger("beets-statistics") @@ -61,6 +63,17 @@ async def get_beets_statistics(): templates.env.filters["quote_plus"] = lambda u: quote_plus(u) +@app.middleware("http") +async def add_slow_request_log(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = (time.time() - start_time) * 1000 + logger.debug(f"Completed request in {process_time:.2f} ms") + if process_time > SLOW_REQUEST_THRESHOLD: + logger.warning("Slow log: {process_time:.2f} ms") + return response + + @app.get("/", response_class=HTMLResponse) async def get_general_stats( request: Request,