-
Notifications
You must be signed in to change notification settings - Fork 3
Performance: 위치 검색창 디바운스·AbortController 적용으로 중복 요청 제거 #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
Walkthrough검색 훅에서 스로틀을 제거하고 디바운스 기반 호출로 전환했습니다. AbortController를 도입해 진행 중 요청 취소와 동일 파라미터 요청 중복 방지 로직을 추가했으며, AbortError는 무시하고 그 외 오류만 처리합니다. API 유틸은 AbortSignal을 전달·전파하도록 시그니처를 확장했습니다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant UI as SearchInput
participant HK as useSearchPlacesHooks
participant AC as AbortController
participant API as searchPlaces()
participant BE as fetch/http
U->>UI: 키워드 입력
UI->>HK: 디바운스된 키워드 변경
alt 키워드 비어있음
HK-->>API: (호출 안 함)
HK->>HK: 결과 초기화, 진행 중 요청 abort
else 키워드 있음
HK->>AC: 기존 요청 abort, 새 컨트롤러 생성
HK->>HK: 동일 (keyword,page,append) 중복 여부 확인
alt 중복 요청
HK-->>API: 스킵
else 신규 요청
HK->>API: searchPlaces({ keyword, page, append, signal })
API->>BE: fetch(..., { signal })
alt 성공
BE-->>API: 응답 데이터
API-->>HK: 결과 반환
HK->>HK: 상태 업데이트(append 여부 반영)
else AbortError
BE--x API: AbortError throw
API--x HK: AbortError 전파
HK->>HK: 오류 무시(로딩 정리)
else 기타 오류
BE-->>API: 오류
API--x HK: 오류 전파
HK->>HK: (append 아님) 로그/노티
end
end
end
note over HK: 언마운트 시 AC.abort()로 정리
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Failed to generate code suggestions for PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/features/rental/search/hook/useSearchPlacesHooks.ts (1)
53-105: StrictMode에서 검색이 멈추는 중대한 회귀Line 53~105의
lastReqRef가드가 동일 키 연속 호출을 전부 막고 있는데, React 18 StrictMode에서는 이펙트가 즉시 정리되고 재실행되면서 첫 번째 호출을abort()로 끊은 뒤 두 번째 호출이 같은 키라는 이유로 아예 실행되지 않습니다. 개발 모드뿐 아니라 추후 재시도(동일 키 재검색)도 영구적으로 차단됩니다. 요청이 진행 중일 때만 중복을 막도록, 완료/중단 시lastReqRef를 초기화하는 등 가드를 수정해 주세요.try { … } catch (error) { … } finally { + lastReqRef.current = null; setIsLoading(false); setIsLoadingMore(false); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
src/features/rental/search/hook/useSearchPlacesHooks.ts(5 hunks)src/features/rental/search/hook/useSearchPosHooks.ts(2 hunks)src/features/rental/search/utils/address/searchPlaces.ts(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/features/rental/search/hook/useSearchPosHooks.ts (2)
src/features/rental/search/utils/address/searchPlaces.ts (1)
PlaceSearchResult(2-10)src/shared/lib/queryClient.ts (1)
queryClient(3-10)
#️⃣ 연관된 이슈
1) 도입 배경
위치 검색창 입력 시 디바운싱과 쓰로틀링을 중첩 적용하여, 사용자가
서울시 강남구등 한글을 타이핑할 때마다 최대 22회의 API 호출이 발생했습니다.React 18의 StrictMode 더블 마운트와 AbortController 부재로 인해 모든 요청이 완료될 때까지 진행되어, 불필요한 네트워크 비용 및 렌더링 과부하가 발생했습니다.
주요 문제점
디바운스 + 쓰로틀중첩으로 멈춤마다 1회 + 경계 1회 추가 호출2) 작업 내용
1️⃣ 디바운스 단일화
useThrottle) 완전 제거2️⃣ StrictMode 중복 호출 가드
lastReqRef도입 →(keyword, page, append)조합으로 요청 키 생성3️⃣ AbortController 적용
controllerRef로 이전 요청 추적abort()로 기존 요청 강제 취소signal을 fetch 옵션에 전달해 중간 요청 즉시 중단useEffectclean-up 시점에서도 abort 실행3) 핵심 코드 스니펫
✅ 1. 디바운스 단일화 (스로틀 제거)
✅ 2. StrictMode 중복 호출 가드
✅ 3. AbortController 도입
✅ 4. fetch signal 전달
성능 최적화 전후 비교
1. API 호출 횟수 개선 및 네트워크 요청 중첩 제거
2. 전체 타임라인 범위 감소 및 INP(입력 응답 시간) 개선
5. 요약 수치 비교