-
Notifications
You must be signed in to change notification settings - Fork 0
채팅 기록 조회 API 개발 #141
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
Merged
Merged
채팅 기록 조회 API 개발 #141
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
a3e6503 to
1554f5c
Compare
📊 코드 커버리지 리포트
|
minibr
reviewed
Dec 19, 2025
b7cc386 to
30c60d3
Compare
Contributor
Author
|
링크 제공 시 요약 정보 포함(#158) 작업에 의존성이 존재합니다. |
30c60d3 to
1374cbb
Compare
Contributor
|
채팅의 시간, 피드백 여부 등도 포함되어야 할 것 같습니다. 어떻게 생각하시나요? |
Contributor
Author
채팅 생성 시간을 전달하도록 수정하였습니다. |
1501671 to
df6677d
Compare
Contributor
PR의 본문에 포함안된 부분이 있어, 포함이 안되는것으로 착각했습니다. |
Goder-0
reviewed
Jan 2, 2026
Goder-0
approved these changes
Jan 2, 2026
df6677d to
6009994
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
관련 이슈
PR 설명
작업 내용
1. API 명세 구현 (
ChatController)GET /v1/chats/{chatId}lastId(커서, 첫 조회 시 null),size(기본 20)MessagesRes(메시지 목록, 다음 페이지 여부, 마지막 ID 반환).messages) 내부에 링크 목록(links)이 포함되며, 각 링크는summary(요약 내용) 필드를 가집니다.{ "success": true, "status": "OK", "message": "채팅 기록을 가져오는데 성공했습니다.", "data": { "messages": [ { "id": 105, "content": "JPA N+1 문제는 Batch Size로 해결할 수 있습니다. 아래 글을 참고하세요.", "type": "AI", "feedback": "LIKE", "time": "2024-10-31 14:30:00" "links": [ { "id": 12, "title": "JPA N+1 문제 해결 가이드", "url": "https://example.com/jpa-n-plus-1", "imageUrl": "https://example.com/image.png", "summary": "JPA에서 지연 로딩으로 인해 발생하는 N+1 문제의 원인과 해결 방법을 다룹니다." } ] }, { "id": 104, "content": "N+1 문제가 뭐야?", "type": "USER", "time": "2024-10-31 14:31:00" "links": [] } ], "hasNext": true, "lastId": 104 } }size파라미터에 대한 최소(1)/최대(50) 검증 로직을@Validated로 적용함.2. 아키텍처 및 비즈니스 로직
복잡한
JOIN으로 인한 성능 저하를 막기 위해 단계별 조회 및 메모리 조립 전략을 사용했습니다.MessageQueryService)No-Offset페이징(id < lastId)을 사용하여 메시지 목록을 빠르게 조회합니다.Message와Link관계는default_batch_fetch_size설정을 통해IN쿼리로 최적화했습니다.SummaryQueryService)Link목록을 추출합니다.findAllByLinkInAndSelectedTrue를 호출하여, 관련된 **대표 요약(Selected Summary)**들을 단 한 번의 쿼리(IN절)로 가져옵니다.MessageService)Map<LinkId, Summary>형태로 변환하여 메모리에 올립니다.MessageDto를 생성합니다.3. 메시지-링크 연관관계 리팩토링 (성능 최적화)
Message):List<Long> linkIds를 삭제하고@ManyToMany(List<Link>) 관계로 변경하여 객체 지향적인 설계를 적용함.@JoinTable적용: 연결 테이블(message_link)을 매핑하기 위해 별도의 중간 엔티티 클래스(예:MessageLink)를 생성하지 않고, 어노테이션만으로 간결하게 다대다 관계를 풀어냄.Cascade옵션을 미설정하여 메시지 삭제가 원본 링크 데이터에 영향을 주지 않도록 함.application.yml):default_batch_fetch_size: 100설정을 추가함.JOIN FETCH없이도 연관된 링크 엔티티를IN쿼리로 묶어서 조회하여, 페이징 시 메모리 이슈를 방지하고 쿼리 성능을 최적화함.4. Repository 및 성능 최적화
WHERE m.id < :lastId조건을 사용하여 데이터 양이 늘어나도 조회 속도가 유지되도록 함.MessageRepository):Feedback은@OneToOne이므로LEFT JOIN FETCH를 유지하되,Links는 Batch Fetching을 활용하므로JOIN을 제거하여 쿼리를 단순화함.3. Entity 및 DTO 구조 개선
Message):List<Long> linkIds를 제거하고@ManyToMany(List<Link>) 관계로 변경하여 객체 그래프 탐색이 가능하도록 수정했습니다.@JoinTable을 사용하여 중간 엔티티 클래스 없이 깔끔하게 매핑했습니다.LinkCardRes,MessageRes):LinkCardRes에summary필드를 추가했습니다.Link와Summary엔티티를 조합하여 DTO로 변환하도록 구현했습니다.4. 테스트 작성
ChatIntegrationTest):MessageServiceTest):summaryQueryService가 호출되어 링크에 맞는 요약 정보를 가져오는지(Map핑 로직) 검증했습니다.SummaryRepositoryTest):IN쿼리를 통해 여러 링크의 대표 요약본이 한 번에 조회되는지 확인했습니다.