perf: AdminSchedule 달력 렌더링 성능 최적화

- scheduleDateMap useMemo로 O(1) 조회 구현
- hasSchedule, getScheduleColor 함수 배열 순회 제거
This commit is contained in:
caadiq 2026-01-09 17:53:58 +09:00
parent 4619d101f0
commit 494c2a9d6d

View file

@ -80,9 +80,9 @@ function AdminSchedule() {
} }
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]); }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]);
// selectedDate undefined (null ) // selectedDate
useEffect(() => { useEffect(() => {
if (selectedDate === undefined) { if (!selectedDate) {
setSelectedDate(getTodayKST()); setSelectedDate(getTodayKST());
} }
}, []); }, []);
@ -166,22 +166,28 @@ function AdminSchedule() {
return colors[color] || 'bg-gray-100 text-gray-700'; 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 hasSchedule = (day) => {
const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
return schedules.some(s => { return scheduleDateMap.has(dateStr);
const scheduleDate = formatDate(s.date);
return scheduleDate === dateStr;
});
}; };
// // (O(1))
const getScheduleColor = (day) => { const getScheduleColor = (day) => {
const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
const schedule = schedules.find(s => { const schedule = scheduleDateMap.get(dateStr);
const scheduleDate = formatDate(s.date);
return scheduleDate === dateStr;
});
if (!schedule) return null; if (!schedule) return null;
const cat = categories.find(c => c.id === schedule.category_id); const cat = categories.find(c => c.id === schedule.category_id);
return cat?.color || '#4A7C59'; return cat?.color || '#4A7C59';