perf(log_db_metrics): fast path in _is_exception_related_to_db to avoid Prisma import

Check exception module (prisma/httpx) before importing Prisma, which is
expensive on first load (~12s). Non-DB exceptions return False without import.
This commit is contained in:
Alexsander Hamir 2026-02-09 17:46:54 -08:00
parent 0779d24f8f
commit 79bdbd2506

View file

@ -103,9 +103,15 @@ def log_db_metrics(func):
def _is_exception_related_to_db(e: Exception) -> bool:
"""
Returns True if the exception is related to the DB
Returns True if the exception is related to the DB (PrismaError, httpx connection/timeout).
Uses a fast path: if the exception is not from prisma or httpx modules, return False
without importing Prisma (which is expensive ~12s on first load).
"""
mod = type(e).__module__
if not (mod.startswith("prisma") or mod.startswith("httpx")):
return False
import httpx
from prisma.errors import PrismaError