fix: Implement pagination to bypass Supabase 1000 row hard limit
This commit is contained in:
parent
cfb8079809
commit
c1223c1f14
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user