INNER CODE UNIT · Python

slow_query_example

doganarif/fastapi-radar · example_app.py:258

async def slow_query_example(db: Session = Depends(get_db)):
    """Example endpoint that performs a slow query."""
    # This query will be highlighted as slow in Radar
    import time

    # Simulate a slow query
    products = db.query(Product).all()
    time.sleep(0.2)  # Simulate slow processing

    # Multiple queries to show query count
    for product in products[:3]:
        _ = db.query(User).filter(User.id == 1).first()

    return {
        "message": "This endpoint performs slow queries",
        "product_count": len(products),
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…