Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 작곡가 목록 조회 API( Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이번 PR은 작곡가 목록 조회 시 스토리 게시글 통계 정보를 추가하는 기능이네요. N+1 문제를 방지하기 위해 단일 쿼리로 모든 작곡가의 통계를 한 번에 집계하는 접근 방식이 좋습니다. 전반적으로 코드가 잘 작성되었지만, 몇 가지 개선할 점이 보입니다.
한 가지는 단일 작곡가 조회 API에서 통계 정보가 누락되어 API 간 데이터 정합성이 맞지 않는 부분입니다. 다른 하나는 QueryDSL을 더 효율적이고 관용적인 방법으로 사용할 수 있는 부분에 대한 제안입니다. 자세한 내용은 각 파일에 남긴 주석을 확인해주세요.
| Composer composer = entityUtils.getEntity(composerId, Composer.class); | ||
| boolean isLiked = user != null && composerLikeRepository.existsByComposerIdAndUserId(composerId, user.getId()); | ||
| ComposerResponseDto composerDto = ComposerResponseDto.from(composer, isLiked); | ||
| ComposerResponseDto composerDto = ComposerResponseDto.from(composer, isLiked, null); |
There was a problem hiding this comment.
ComposerResponseDto.from 메서드 시그니처 변경으로 인해 null을 전달하도록 수정하신 것으로 보입니다. 하지만 이렇게 되면 /composers/{composerId}/posts 엔드포인트의 응답에서 storyPostCount는 항상 0, lastStoryPostAt은 항상 null이 되어 /composers 목록 조회 API와 데이터 정합성이 맞지 않게 됩니다.
단일 작곡가에 대한 통계도 조회하여 ComposerResponseDto를 생성할 때 함께 전달하는 것이 좋겠습니다. PostQueryRepository에 단일 작곡가의 통계를 조회하는 메서드를 추가하여 해결할 수 있습니다.
| List<Tuple> results = queryFactory | ||
| .select( | ||
| storyPost.primaryComposer.id, | ||
| storyPost._super.id.count(), | ||
| storyPost._super.createdAt.max() | ||
| ) | ||
| .from(storyPost) | ||
| .where( | ||
| storyPost._super.isBlocked.isFalse() | ||
| .and(storyPost._super.postStatus.eq(PostStatus.PUBLISHED)) | ||
| ) | ||
| .groupBy(storyPost.primaryComposer.id) | ||
| .fetch(); | ||
|
|
||
| return results.stream().collect(Collectors.toMap( | ||
| tuple -> tuple.get(storyPost.primaryComposer.id), | ||
| tuple -> new StoryPostStatsDto( | ||
| tuple.get(storyPost._super.id.count()), | ||
| tuple.get(storyPost._super.createdAt.max()) | ||
| ) | ||
| )); |
There was a problem hiding this comment.
현재 구현은 fetch()로 List<Tuple>을 가져온 후, stream을 사용해 Map으로 변환하고 있습니다. 이는 올바르게 동작하지만, QueryDSL의 transform과 groupBy를 사용하면 더 간결하고 효율적인 코드를 작성할 수 있습니다. transform을 사용하면 중간 단계의 List 생성 없이 바로 Map을 생성할 수 있습니다.
아래와 같이 리팩토링하는 것을 고려해보세요.
| List<Tuple> results = queryFactory | |
| .select( | |
| storyPost.primaryComposer.id, | |
| storyPost._super.id.count(), | |
| storyPost._super.createdAt.max() | |
| ) | |
| .from(storyPost) | |
| .where( | |
| storyPost._super.isBlocked.isFalse() | |
| .and(storyPost._super.postStatus.eq(PostStatus.PUBLISHED)) | |
| ) | |
| .groupBy(storyPost.primaryComposer.id) | |
| .fetch(); | |
| return results.stream().collect(Collectors.toMap( | |
| tuple -> tuple.get(storyPost.primaryComposer.id), | |
| tuple -> new StoryPostStatsDto( | |
| tuple.get(storyPost._super.id.count()), | |
| tuple.get(storyPost._super.createdAt.max()) | |
| ) | |
| )); | |
| return queryFactory | |
| .from(storyPost) | |
| .where( | |
| storyPost._super.isBlocked.isFalse() | |
| .and(storyPost._super.postStatus.eq(PostStatus.PUBLISHED)) | |
| ) | |
| .groupBy(storyPost.primaryComposer.id) | |
| .transform(com.querydsl.core.group.GroupBy.groupBy(storyPost.primaryComposer.id).as( | |
| com.querydsl.core.types.Projections.constructor(StoryPostStatsDto.class, | |
| storyPost._super.id.count(), | |
| storyPost._super.createdAt.max() | |
| ) | |
| )); |
Summary
GET /composers응답에storyPostCount,lastStoryPostAt필드 추가storyPostCount: 0,lastStoryPostAt: null반환Changes
StoryPostStatsDto신규 레코드 추가PostQueryRepository.findStoryPostStatsByAllComposers()메서드 추가ComposerResponseDto에storyPostCount,lastStoryPostAt필드 추가ComposerQueryService에서 통계 맵 일괄 조회 후 DTO 생성 시 주입Test plan
ComposerQueryServiceTest.storyPostStats_returnedCorrectly— PUBLISHED만 집계, DRAFT 제외 확인ComposerQueryControllerTest두 엔드포인트 REST Docs 스니펫 생성 확인GET /composers응답에storyPostCount,lastStoryPostAt포함 여부 확인