-
Notifications
You must be signed in to change notification settings - Fork 1
[SCRUM-350] Refactor: 좋아요 집계 기간 변경 #115
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인기 게시물 조회 기간을 72시간에서 7일로 변경했다. Repository의 메서드명을 7일 기준으로 수정했고, Service에서 계산 변수를 7일 기준으로 바꾸고 해당 메서드를 호출하도록 업데이트했다. 쿼리 내용과 반환 타입, 매핑 로직은 변경되지 않았다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Service as CommunityService
participant Repo as CommunityPostRepository
participant DB
Client->>Service: getPopularPosts()
Service->>Service: since = now - 7 days
Service->>Repo: findTop3ByLikesSince7Days(since)
Repo->>DB: JPQL 쿼리 실행 (since 기준, 좋아요 수 정렬, LIMIT 3)
DB-->>Repo: 상위 3개 게시물
Repo-->>Service: List<CommunityPost>
Service-->>Client: PopularWrappingResponse
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/java/com/kkinikong/be/community/repository/communityPost/CommunityPostRepository.java (2)
14-14: @param import이 잘못되어 바인딩이 동작하지 않습니다.Spring Data JPA의
@Param이 아니라 Lettuce의 어노테이션을 임포트하고 있습니다. 현재 상태로는:since파라미터 바인딩이 실패합니다.다음으로 교체하세요:
- import io.lettuce.core.dynamic.annotation.Param; + import org.springframework.data.repository.query.Param;
23-31: JPQL에서 LIMIT는 지원되지 않습니다 — 제거하고 메서드명 Top3에 맡기세요.Hibernate JPQL에
LIMIT 3는 유효하지 않습니다. 메서드명이findTop3...이므로 Spring Data가 자동으로 최대 3건 제한을 적용합니다. 중복/비표준 구문을 제거하세요.@Query( """ SELECT cp FROM CommunityPost cp LEFT JOIN CommunityPostLike cpl ON cp.id = cpl.communityPost.id WHERE cpl.createdDate >= :since GROUP BY cp.id ORDER BY COUNT(cpl.id) DESC, cp.viewCount DESC - LIMIT 3 """)
🧹 Nitpick comments (5)
src/main/java/com/kkinikong/be/community/repository/communityPost/CommunityPostRepository.java (3)
25-31: LEFT JOIN + WHERE 조건으로 인해 사실상 INNER JOIN으로 동작 — 의도 확인 및 ON 절로 이동 제안.
WHERE cpl.createdDate >= :since가 NULL을 제거하여 INNER JOIN과 동일하게 됩니다. 진짜 LEFT JOIN 의미(좋아요 0건인 글 포함)를 원한다면 필터를 ON 절로 옮기세요. 반대로 최소 1건 이상 좋아요가 있는 글만 원한다면 현재도 문제는 없지만 명시적으로 표현하는 편이 좋습니다.대안 JPQL(연관 경로 사용, LIMIT 제거):
@Query( """ - SELECT cp FROM CommunityPost cp - LEFT JOIN CommunityPostLike cpl ON cp.id = cpl.communityPost.id - WHERE cpl.createdDate >= :since + SELECT cp FROM CommunityPost cp + LEFT JOIN cp.communityPostLikeList cpl ON cpl.createdDate >= :since GROUP BY cp.id ORDER BY COUNT(cpl.id) DESC, cp.viewCount DESC """)
32-32: 기간을 메서드명에 하드코딩하지 말고 일반화 권장.요구사항 변경 때마다 시그니처를 바꾸지 않도록
findTop3ByLikesSince(...)처럼 범용 이름을 권장합니다. 서비스에서 기간(3일→7일→N일)은 계산해since로 전달하세요.
25-30: 집계 성능을 위해 인덱스 확인.
CommunityPostLike에(created_date, community_post_id)또는(community_post_id, created_date)복합 인덱스가 없으면 7일 윈도우 스캔 비용이 큽니다. 운영 트래픽 대비 인덱스 전략을 점검하세요.src/main/java/com/kkinikong/be/community/service/CommunityService.java (2)
166-175: 캐시 TTL/무효화 전략 재점검 필요.메서드 파라미터가 없어 기본 키로 전역 캐시됩니다. 7일 윈도우 특성상 TTL이 너무 길면 인기글이 갱신되지 않습니다. 캐시 TTL(예: 수분~수십분)과 키 전략(카테고리별 등)을 확인하세요.
unless조건은 현재 항상 false로(비null) 사실상 효과가 없습니다.
168-168: 시간 의존 로직은 Clock 주입으로 테스트 가능하게.
LocalDateTime.now()대신Clock을 주입하면 경계 테스트(정확히 7일)와 타임존 이슈를 줄일 수 있습니다.- LocalDateTime since7Days = LocalDateTime.now().minusDays(7); + LocalDateTime since7Days = LocalDateTime.now(clock).minusDays(7);서비스 필드에
private final Clock clock;추가 후 구성 예시:// 예: @Configuration @Bean Clock clock() { return Clock.systemUTC(); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/main/java/com/kkinikong/be/community/repository/communityPost/CommunityPostRepository.java(1 hunks)src/main/java/com/kkinikong/be/community/service/CommunityService.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/java/com/kkinikong/be/community/repository/communityPost/CommunityPostRepository.java (1)
src/main/java/com/kkinikong/be/community/domain/CommunityPost.java (1)
Table(26-114)
src/main/java/com/kkinikong/be/community/service/CommunityService.java (2)
src/main/java/com/kkinikong/be/community/domain/CommunityPost.java (1)
Table(26-114)src/main/java/com/kkinikong/be/community/dto/response/CommunityPostPopularResponse.java (1)
CommunityPostPopularResponse(5-9)
🔇 Additional comments (2)
src/main/java/com/kkinikong/be/community/service/CommunityService.java (2)
168-175: 3일→7일 변경 LGTM.윈도우 계산과 리포지토리 호출이 일관되게 업데이트되었습니다.
171-171: 레거시 메서드 호출 잔존 여부를 수동으로 최종 확인하세요.
findTop3ByLikesSince72Hours와since72Hours에 대한 검색 결과가 없으나, 스크립트만으로는 누락될 수 있어 전체 코드베이스를 직접 점검해 주세요.
📝 개요
3일 -> 7일로 변경
🛠️ 작업 사항
🔗 관련 이슈 / JIRA
✅ 체크리스트
🙏 기타 사항
추가적으로 리뷰어가 알아야 할 사항 작성
Summary by CodeRabbit