Skip to content

Conversation

@kyoooooong
Copy link
Contributor

@kyoooooong kyoooooong commented Feb 12, 2025

#️⃣ 요약 설명

📝 작업 내용

  1. 예외 처리시 JOBID가 아니라 JOB을 기준으로 하도록 수정하였습니다.
  2. 패치 조인으로 가져올 때에 함수를 조금 수정하였습니다.

코드의 흐름이나 중요한 부분을 작성해주세요.

// 핵심 코드를 붙여넣기 해주세요

코드에 대한 간단한 설명 부탁드립니다.

동작 확인

기능을 실행했을 때 정상 동작하는지 여부를 확인하고 사진을 올려주세요

ex) 테스트 코드 작성후 성공 사진
ex) swagger 사진

💬 리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

Summary by CodeRabbit

  • Bug Fixes

    • 콘텐츠 스크랩 데이터를 불러올 때, 멤버의 작업 정보 누락으로 인한 오류 발생 가능성을 개선했습니다.
  • Refactor

    • 관련 작업 정보를 한 번에 불러올 수 있도록 데이터 조회 방식을 최적화하여 사용자 경험을 더욱 안정적으로 개선했습니다.
  • Documentation

    • API 엔드포인트 설명을 사용자의 현재 직무 기준으로 스크랩한 콘텐츠를 조회하는 내용으로 수정했습니다.

@kyoooooong kyoooooong added the fix 버그/에러 수정 label Feb 12, 2025
@kyoooooong kyoooooong self-assigned this Feb 12, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

본 PR은 ContentScrapRepositoryContentScrapService 클래스의 변경 사항을 포함합니다.
ContentScrapRepository에서는 기존의 findByMemberAndJobId 메서드를 제거하고, 관련 Job 엔티티를 함께 조회하기 위해 JOIN FETCH를 포함한 findByMemberAndJobIdWithFetch 메서드를 도입했습니다.
ContentScrapService에서는 job ID 체크 로직을 member.getJob() 존재 여부 확인으로 변경하여 null 참조 예외를 방지하고, 업데이트된 레포지토리 메서드를 호출하도록 수정했습니다.
또한, ContentController의 API 문서에서 스크랩된 콘텐츠를 조회하는 맥락을 명확히 하기 위해 설명이 수정되었습니다.

Changes

파일 변경 요약
src/.../repository/ContentScrapRepository.java 기존 findByMemberAndJobId 제거, JOIN FETCH 포함한 findByMemberAndJobIdWithFetch 추가
src/.../service/ContentScrapService.java job 체크 로직을 member.getJob() 확인으로 변경, 업데이트된 레포지토리 메서드 호출 적용
src/.../controller/ContentController.java getScrapContents 메서드의 문서화 내용 수정, 스크랩 콘텐츠 조회의 맥락을 명확히 함

Possibly related PRs

Suggested reviewers

  • jpark0506
  • KSLEE19
  • veronees
  • jjeongdong

Poem

토끼가 읊조리는 코드의 노래
깡총깡총 뛰며 변경을 전해요
fetch로 잡은 데이터 반짝이며
null의 그림자 멀리 날려버리고
코드 숲 속에 행복을 심어요 🐇
오늘도 우리는 함께 달려가요!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97571b2 and ea75cee.

📒 Files selected for processing (3)
  • src/main/java/UMC/career_mate/domain/content/controller/ContentController.java (1 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (1 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/UMC/career_mate/domain/content/controller/ContentController.java
  • src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (1)

23-31: 성능 최적화를 위한 JOIN FETCH 사용이 좋습니다만, 페이징 처리 시 주의가 필요합니다.

JOIN FETCH를 사용하여 N+1 문제를 해결한 것은 좋은 접근입니다. 하지만 JOIN FETCH와 페이징(Pageable)을 함께 사용할 때 몇 가지 고려사항이 있습니다:

  1. 메모리 사용량이 증가할 수 있습니다.
  2. 데이터가 많은 경우 성능 저하가 발생할 수 있습니다.

다음과 같은 대안을 고려해보시는 것은 어떨까요?:

@Query(value = "SELECT DISTINCT cs FROM ContentScrap cs " +
       "JOIN cs.content c " +
       "JOIN c.job j " +
       "WHERE cs.member = :member AND j.id = :jobId",
       countQuery = "SELECT COUNT(DISTINCT cs) FROM ContentScrap cs " +
       "JOIN cs.content c " +
       "JOIN c.job j " +
       "WHERE cs.member = :member AND j.id = :jobId")
Page<ContentScrap> findByMemberAndJobIdWithFetch(
        @Param("member") Member member,
        @Param("jobId") Long jobId,
        Pageable pageable
);

이렇게 수정하면:

  1. DISTINCT를 사용하여 중복을 제거
  2. 별도의 countQuery를 정의하여 정확한 페이징 처리
  3. JOIN FETCH 대신 일반 JOIN을 사용하여 메모리 사용량 최적화
src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (2)

56-60: 에러 메시지 업데이트 필요

null 체크를 jobId에서 job 객체로 변경한 것은 좋은 개선이지만, 에러 메시지(NOT_FOUND_BY_JOB_ID)가 현재 검사 로직과 일치하지 않습니다.

에러 코드를 NOT_FOUND_JOB과 같이 더 명확한 메시지로 변경하는 것을 고려해보세요.


71-75: 페이지네이션 응답이 개선되었습니다.

페이지네이션 응답 구조가 더 명확해졌으며, hasNext 추가로 클라이언트 측에서 더 나은 페이지 처리가 가능해졌습니다.

추가 개선사항으로 totalElementstotalPages도 포함하는 것을 고려해보세요. 이는 클라이언트 측에서 전체 페이지 수를 파악하는데 도움이 될 수 있습니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9f1c7 and ce3ba71.

📒 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 (1 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (1 hunks)
🔇 Additional comments (2)
src/main/java/UMC/career_mate/domain/contentScrap/dto/response/ContentScrapResponseDTO.java (1)

11-11: DTO에 jobId 필드가 적절히 추가되었습니다.

스크랩된 컨텐츠와 관련된 Job을 식별하기 위한 필드가 올바르게 추가되었습니다.

src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (1)

64-65: 성능 최적화가 잘 이루어졌습니다!

JOIN FETCH를 활용하여 N+1 문제를 해결한 것이 좋은 개선입니다. 또한 주석을 통해 변경 의도가 명확히 전달되었습니다.

Copy link
Member

@momuzzi momuzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM~ 고생하셨습니다

String title,
String url,
String photo,
Long jobId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converter에서 jobId 처리 추가해야할 거 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 잘못 들어가서 빼두었습니다..! 나머지도 모두 수정해두었습니다

Page<ContentScrap> findByMemberAndJobId(@Param("member") Member member, @Param("jobId") Long jobId, Pageable pageable);
@Query("SELECT cs FROM ContentScrap cs " +
"JOIN FETCH cs.content c " +
"JOIN FETCH c.job j " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job 페치 조인은 안해도 괜찮을 것 같습니다~

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (1)

27-31: 메서드 이름에 대한 제안

현재 메서드 이름 findByMemberAndJobIdWithFetch는 구현 세부사항을 포함하고 있습니다. 비즈니스 의도를 더 잘 표현하는 이름을 고려해보세요.

다음과 같은 이름을 제안드립니다:

-    Page<ContentScrap> findByMemberAndJobIdWithFetch(
+    Page<ContentScrap> findScrapsByMemberAndJobId(
            @Param("member") Member member,
            @Param("jobId") Long jobId,
            Pageable pageable
    );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce3ba71 and e9d01c2.

📒 Files selected for processing (2)
  • src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (1 hunks)
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/UMC/career_mate/domain/contentScrap/service/ContentScrapService.java
🔇 Additional comments (1)
src/main/java/UMC/career_mate/domain/contentScrap/repository/ContentScrapRepository.java (1)

23-31: 성능 최적화를 위한 JOIN FETCH 쿼리 검토가 필요합니다.

현재 구현된 쿼리에서 다음 사항들을 고려해 주시기 바랍니다:

  1. 이전 리뷰어의 의견처럼 job 엔티티에 대한 페치 조인이 실제로 필요한지 검토가 필요합니다.
  2. 페이징 처리와 함께 여러 개의 페치 조인을 사용하면 메모리 이슈가 발생할 수 있습니다.

성능 최적화를 위해 다음과 같이 수정하는 것을 고려해보세요:

    @Query("SELECT cs FROM ContentScrap cs " +
            "JOIN FETCH cs.content c " +
-            "JOIN FETCH c.job j " +
+            "JOIN c.job j " +
            "WHERE cs.member = :member AND j.id = :jobId")

@kyoooooong kyoooooong force-pushed the feature/CMAT-63 branch 2 times, most recently from 22192b4 to 97571b2 Compare February 12, 2025 17:12
@KSLEE19 KSLEE19 merged commit edcd34e into develop Feb 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그/에러 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants