From 494c2a9d6d25139422e6136b3070ac35e876699b Mon Sep 17 00:00:00 2001 From: caadiq Date: Fri, 9 Jan 2026 17:53:58 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20AdminSchedule=20=EB=8B=AC=EB=A0=A5=20?= =?UTF-8?q?=EB=A0=8C=EB=8D=94=EB=A7=81=20=EC=84=B1=EB=8A=A5=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scheduleDateMap useMemo로 O(1) 조회 구현 - hasSchedule, getScheduleColor 함수 배열 순회 제거 --- frontend/src/pages/pc/admin/AdminSchedule.jsx | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/frontend/src/pages/pc/admin/AdminSchedule.jsx b/frontend/src/pages/pc/admin/AdminSchedule.jsx index 9eda0d5..d29e14e 100644 --- a/frontend/src/pages/pc/admin/AdminSchedule.jsx +++ b/frontend/src/pages/pc/admin/AdminSchedule.jsx @@ -80,9 +80,9 @@ function AdminSchedule() { } }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]); - // selectedDate가 undefined이면 오늘 날짜로 초기화 (null은 전체보기이므로 유지) + // selectedDate가 없으면 오늘 날짜로 초기화 useEffect(() => { - if (selectedDate === undefined) { + if (!selectedDate) { setSelectedDate(getTodayKST()); } }, []); @@ -166,22 +166,28 @@ function AdminSchedule() { return colors[color] || 'bg-gray-100 text-gray-700'; }; - // 해당 날짜에 일정이 있는지 확인 + // 일정 날짜별 맵 (O(1) 조회용) - 성능 최적화 + const scheduleDateMap = useMemo(() => { + const map = new Map(); + schedules.forEach(s => { + const dateStr = formatDate(s.date); + if (!map.has(dateStr)) { + map.set(dateStr, s); + } + }); + return map; + }, [schedules]); + + // 해당 날짜에 일정이 있는지 확인 (O(1)) const hasSchedule = (day) => { const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; - return schedules.some(s => { - const scheduleDate = formatDate(s.date); - return scheduleDate === dateStr; - }); + return scheduleDateMap.has(dateStr); }; - // 해당 날짜의 첫 번째 일정 카테고리 색상 + // 해당 날짜의 첫 번째 일정 카테고리 색상 (O(1)) const getScheduleColor = (day) => { const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; - const schedule = schedules.find(s => { - const scheduleDate = formatDate(s.date); - return scheduleDate === dateStr; - }); + const schedule = scheduleDateMap.get(dateStr); if (!schedule) return null; const cat = categories.find(c => c.id === schedule.category_id); return cat?.color || '#4A7C59';