From 124b50af53582c6f5558c52b6e6bfc170a053784 Mon Sep 17 00:00:00 2001 From: hyungi Date: Tue, 16 Jun 2026 14:18:12 +0900 Subject: [PATCH] =?UTF-8?q?perf(events):=20list=5Fevents=20total=20?= =?UTF-8?q?=EC=9D=84=20DB=20COUNT=20=ED=91=B8=EC=8B=9C=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=20(R10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 전체 Event.id 를 메모리 로딩 후 len() 하던 것을 select(func.count(Event.id)) 로 전환 — 행 수에 선형이던 메모리/전송 비용 제거. 결과 동등(단순 카운트라 golden-diff 불요). 검증: py_compile 통과. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/api/events.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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())