diff --git a/app/api/events.py b/app/api/events.py index d6be9ff..6cc8f25 100644 --- a/app/api/events.py +++ b/app/api/events.py @@ -21,7 +21,7 @@ from zoneinfo import ZoneInfo from fastapi import APIRouter, Body, Depends, HTTPException, Query from pydantic import BaseModel, Field -from sqlalchemy import and_, or_, select +from sqlalchemy import and_, func, or_, select from sqlalchemy.ext.asyncio import AsyncSession from core.auth import get_current_user @@ -388,10 +388,10 @@ async def list_events( ) base = select(Event).where(and_(*where)) - total_q = await session.execute( - select(Event.id).where(and_(*where)) - ) - total = len(total_q.scalars().all()) + # R10: 전체 ID 로딩 후 len() 대신 DB COUNT 푸시다운 (행 수 선형 메모리/전송 비용 제거). + total = ( + await session.execute(select(func.count(Event.id)).where(and_(*where))) + ).scalar() or 0 rows = await session.execute( base.order_by(Event.created_at.desc())