From c1223c1f143ea55d47167cb0ccc1541b7cb0eed2 Mon Sep 17 00:00:00 2001 From: haneulai Date: Tue, 27 Jan 2026 16:58:48 +0900 Subject: [PATCH] fix: Implement pagination to bypass Supabase 1000 row hard limit --- app/routers/stats.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/routers/stats.py b/app/routers/stats.py index a09f646..f801f5e 100644 --- a/app/routers/stats.py +++ b/app/routers/stats.py @@ -77,11 +77,23 @@ async def get_plant_stats( stats_query = stats_query.order("date", desc=False) - # Supabase 기본 limit이 1000이므로 충분히 늘려줌 (10년치 = 약 3650일) - stats_result = stats_query.limit(10000).execute() + # Supabase API Limit(1000) 우회를 위한 페이지네이션 + all_stats_data = [] + start = 0 + batch_size = 1000 + while True: + # range는 inclusive index (Start, End) + result = stats_query.range(start, start + batch_size - 1).execute() + batch = result.data + all_stats_data.extend(batch) + + if len(batch) < batch_size: + break + start += batch_size + # 데이터 맵핑 {날짜: 발전량} - data_map = {row["date"]: row["total_generation"] or 0 for row in stats_result.data} + data_map = {row["date"]: row["total_generation"] or 0 for row in all_stats_data} # 2. 오늘 실시간 데이터 조회 (solar_logs) - 오늘이 조회 범위에 포함될 때만 today_generation = 0.0