Skip to content

refactor: TimeTable 최적화 (비동기 처리, 경쟁 조건 해소, 코드 위생)#2

Open
jjamming wants to merge 3 commits intodevfrom
refactor/optimize-timetable
Open

refactor: TimeTable 최적화 (비동기 처리, 경쟁 조건 해소, 코드 위생)#2
jjamming wants to merge 3 commits intodevfrom
refactor/optimize-timetable

Conversation

@jjamming
Copy link
Owner

@jjamming jjamming commented Mar 7, 2026

Summary

TimeTable 컴포넌트의 버그, 경쟁 조건, 코드 중복, 미사용 코드를 개선합니다.

Commit 1: handleSaveClick 비동기 처리 및 불필요한 API 호출 제거

  • usePostTimeSlot에서 mutateAsync 노출
  • handleSaveClickasync/await로 변경하여 mutation 완료 대기
  • refetch() 제거 (onSuccess에서 setQueryData로 캐시 업데이트 중이므로 불필요)
  • 저장 시 API 호출: 2회 → 1회, 데이터 정합성 보장

Commit 2: useEffect 경쟁 조건 해소 - 중복 effect 통합

  • 동일 deps(selectedCarId, selectedWeek)를 가진 2개의 useEffect를 1개로 병합
  • handleCancelClick 호출 대신 직접 상태 초기화 (deps 변경에 의한 불필요한 재실행 방지)
  • 주/차량 변경 시 setState 호출: 7회 → 4회
  • window.requestAnimationFramerequestAnimationFrame 통일

Commit 3: 코드 위생 개선

  • AvailableTimeSlot: hover useState → CSS :hover로 전환 (슬롯당 리렌더링 2회 → 0회)
  • slotMerger: includes 참조 비교 → slotUtils.isSameSlot 값 비교로 수정
  • slotUtils: 미사용 removeSlot, addSlot 함수 제거

Test Plan

  • pnpm build — TypeScript 컴파일 에러 없음 확인
  • pnpm test — 기존 테스트 통과 확인
  • pnpm lint — lint 에러 없음 확인
  • 시간표 저장 시 API 호출 1회만 발생하는지 확인
  • 주/차량 변경 시 시간표가 정상 전환되는지 확인
  • 유휴시간 슬롯 hover 시 스타일 정상 동작 확인
  • 삭제 버튼 hover 시 노출 정상 확인

🤖 Generated with Claude Code

jjamming and others added 3 commits March 7, 2026 22:13
- usePostTimeSlot에서 mutateAsync 노출 (createTimeSlotAsync)
- handleSaveClick을 async/await로 변경하여 mutation 완료 대기
- refetch() 제거 (onSuccess에서 setQueryData로 캐시 업데이트 중이므로 불필요)
- onEditModeChange는 mutation 성공 후 호출

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- selectedCarId/selectedWeek deps를 공유하는 두 개의 useEffect를 단일 effect로 병합
- handleCancelClick 호출 대신 직접 상태 초기화 수행 (deps 변경에 의한 불필요한 effect 재실행 방지)
- rAF로 displayWeek 전환 + showSlots 복원을 단일 effect에서 관리
- window.requestAnimationFrame → requestAnimationFrame 통일

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- AvailableTimeSlot: hover useState → CSS :hover로 전환 (슬롯당 리렌더링 2회 → 0회)
- AvailableTimeSlot: 삭제 버튼 opacity: 0 → :hover opacity: 1 패턴 적용
- slotMerger: includes 참조 비교 → slotUtils.isSameSlot 값 비교로 수정
- slotUtils: 미사용 removeSlot, addSlot 함수 제거

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant