Open
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
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.
✅ 기본 요구사항
API 명세
🗄 데이터베이스
데이터베이스 설정
데이터베이스 환경 설정
ERD를 기반으로 DDL 작성
테이블 생성
작성한 DDL 파일을 src/main/resources/schema.sql 경로에 포함
⚙️ Spring Data JPA 적용
🧩 엔티티 정의
공통 엔티티 추상 클래스
패키지
com.sprint.mission.discodeit.entity.base
Auditing 적용
사용 어노테이션
도메인 참조 관계 수정
연관관계 매핑 정리
PR 첨부 내용
다음 기준으로 정리
JPA 연관관계 매핑
다음 어노테이션을 활용하여 ERD 반영
영속성 전이 및 고아 객체 설정
🗃 Repository와 Service에 JPA 도입
서비스 레이어 수정
영속성 컨텍스트 특성 반영
📦 DTO 적극 도입
Entity를 Controller에 직접 노출했을 때 문제점
PR 첨부 내용
-> DTO를 사용하면 필요한 데이터만 서비스 계층에서 조회하여 전달할 수 있어 이러한 문제를 예방 가능
DTO 정의
Mapper 컴포넌트 구현
패키지
com.sprint.mission.discodeit.mapper
📁 BinaryContent 저장 로직 고도화
BinaryContent 엔티티 수정
BinaryContentStorage 인터페이스 설계
패키지
com.sprint.mission.discodeit.storage
역할
서비스 로직 리팩토링
BinaryContent 다운로드 API
엔드포인트
GET /api/binaryContents/{binaryContentId}/download
로컬 스토리지 구현
Bean 등록 조건
discodeit.storage.type=local
스토리지 설정
설정값
discodeit.storage.local.root-path
구현 내용
📄 페이징과 정렬
메시지 목록 조회
PageResponse DTO
패키지
com.sprint.mission.discodeit.dto.response
구성
PageResponse Mapper
패키지
com.sprint.mission.discodeit.mapper
🚀 심화 요구사항
N+1 문제 해결
읽기 전용 트랜잭션 활용
설정
spring.jpa.open-in-view=false
페이지네이션 최적화
Offset vs Cursor Pagination
PR 첨부 내용
Offset Pagination
Offset Pagination은 페이지 번호와 페이지 크기를 기반으로 데이터를 조회하는 방식으로
page=2, size=50과 같이 요청하면 데이터베이스에서는 offset과 limit을 활용하여 데이터를 조회함
특징
offset이 매우 커질 경우 데이터베이스는 많은 데이터를 스캔한 뒤 일부만 반환하게 되므로 성능 문제가 발생할 수 있음
Cursor Pagination
Cursor Pagination은 마지막으로 조회한 데이터의 기준 값(cursor)을 기반으로 다음 데이터를 조회하는 방식으로
예를 들자면, 마지막으로 조회한 메시지의 createdAt이나 id 값을 기준으로 다음 데이터를 조회함
특징
Cursor Pagination은 이전 페이지의 마지막 데이터를 기준으로 조회하기 때문에 offset 방식처럼 불필요한 데이터를 스캔하지 않아 성능상 이점이 있음
정리 항목
커서 기반 페이지네이션 적용
🧰 MapStruct 적용
💻 실행 결과