-
Notifications
You must be signed in to change notification settings - Fork 0
[CMAT-63] fix: 스크랩한 컨텐츠 조회 API 수정 #44
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
Walkthrough이번 PR에서는 Changes
Sequence Diagram(s)sequenceDiagram
participant M as Member
participant S as ContentScrapService
participant R as ContentScrapRepository
M->>S: getScrapContents(member, page, size)
S->>S: member.getJob() 여부 확인
alt job 정보 없음
S->>M: 기본/빈 응답 반환
else job 정보 존재
S->>R: 멤버의 전체 스크랩 조회 요청
R-->>S: 모든 스크랩 데이터 반환
S->>S: jobId 기준으로 스크랩 필터링
S->>M: 필터링된 스크랩과 페이지네이션 정보 포함 응답 반환
end
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/UMC/career_mate/domain/contentScrap/dto/response/ContentScrapResponseDTO.java(1 hunks)src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java(0 hunks)src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java
🔇 Additional comments (4)
src/main/java/UMC/career_mate/domain/contentScrap/dto/response/ContentScrapResponseDTO.java (2)
11-11: 적절한 필드 추가입니다!
jobId필드를 추가함으로써 다음과 같은 이점이 있습니다:
- Job 기반의 컨텐츠 필터링이 가능해집니다
- ID 필드 타입(Long)의 일관성을 유지합니다
- 스크랩된 컨텐츠 조회 API의 요구사항을 잘 반영합니다
5-13: 전반적인 구조가 잘 설계되어 있습니다!
- Record를 사용하여 불변성을 보장합니다
- Builder 패턴을 통해 객체 생성의 유연성을 제공합니다
- 필드들이 논리적으로 잘 정렬되어 있습니다
src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (2)
56-60: Job 객체를 직접 검증하도록 개선되었습니다!
jobId대신job객체를 직접 검증하도록 변경한 것은 좋은 개선입니다. 이는 더 객체지향적이며 도메인 모델을 더 잘 반영합니다.
71-77: 페이지네이션 정확성 검증이 필요합니다.필터링 이후 실제 반환되는 데이터 크기가 요청된 페이지 크기와 다를 수 있습니다. 또한
hasNext값이 필터링 전의 전체 데이터를 기준으로 계산되어 부정확할 수 있습니다.페이지네이션 로직이 의도한 대로 동작하는지 확인해주세요:
- 필터링 후 빈 페이지가 반환되는 경우
- 마지막 페이지의
hasNext값이 정확한지- 실제 클라이언트가 요청한 size만큼의 데이터가 반환되는지
| Page<ContentScrap> allScraps = contentScrapRepository.findByMember(member, pageRequest); | ||
|
|
||
| List<ContentScrapResponseDTO> contentList = scraps.stream() | ||
| List<ContentScrapResponseDTO> contentList = allScraps.stream() | ||
| .filter(scrap -> scrap.getContent().getJob().getId().equals(jobId)) | ||
| .map(ContentScrapConverter::toContentScrapResponseDTO) | ||
| .toList(); |
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.
🛠️ Refactor suggestion
성능 최적화가 필요할 수 있습니다.
현재 구현은 다음과 같은 잠재적인 성능 문제가 있습니다:
- 모든 스크랩을 메모리에 로드한 후 필터링하므로 데이터가 많은 경우 메모리 사용량이 증가할 수 있습니다.
scrap.getContent().getJob()호출로 인한 N+1 쿼리 문제가 발생할 수 있습니다.
다음과 같은 개선을 고려해보세요:
@Query("SELECT cs FROM ContentScrap cs " +
"JOIN FETCH cs.content c " +
"JOIN FETCH c.job j " +
"WHERE cs.member = :member AND j.id = :jobId")
Page<ContentScrap> findByMemberAndJobIdWithFetch(
@Param("member") Member member,
@Param("jobId") Long jobId,
Pageable pageable
);
#️⃣ 요약 설명
📝 작업 내용
// 핵심 코드를 붙여넣기 해주세요코드에 대한 간단한 설명 부탁드립니다.
동작 확인
💬 리뷰 요구사항(선택)
Summary by CodeRabbit