diff --git a/hooks/useSchedule.ts b/hooks/useSchedule.ts index db5a713..9486d97 100644 --- a/hooks/useSchedule.ts +++ b/hooks/useSchedule.ts @@ -59,8 +59,16 @@ export const getSchedule = cache(async (year: string | number): Promise { room.sessions.forEach((session) => { const timeKey = format(parseISO(session.startsAt), "HH:mm"); - const existing = sessionsByTime.get(timeKey) || []; - sessionsByTime.set(timeKey, [...existing, session]); + const existing = sessionsByTime.get(timeKey); + if (!existing) { + sessionsByTime.set(timeKey, [session]); + } else { + /* + * ⚡ Bolt: Use amortized O(1) push instead of O(N^2) array spread inside loop + * Impact: Decreases memory consumption and GC pauses for large schedule datasets + */ + existing.push(session); + } }); });