-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 내서재에서 도서검색이 가능하도록 기능을 구현 #61
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
📝 WalkthroughWalkthrough도서관(내서재)에서 도서 제목으로 검색할 수 있도록, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant BookController
participant BookUseCase
participant UserBookService
participant UserBookDomainService
participant UserBookRepository
Client->>BookController: GET /user/library?title=xxx
BookController->>BookUseCase: getUserLibraryBooks(..., title, ...)
BookUseCase->>UserBookService: findUserBooksByDynamicConditionWithStatusCounts(..., title, ...)
UserBookService->>UserBookDomainService: findUserBooksByDynamicCondition(..., title, ...)
UserBookDomainService->>UserBookRepository: findUserBooksByDynamicCondition(..., title, ...)
UserBookRepository-->>UserBookDomainService: Page<UserBook>
UserBookDomainService-->>UserBookService: Page<UserBookInfoVO>
UserBookService-->>BookUseCase: UserBookPageResponse
BookUseCase-->>BookController: UserBookPageResponse
BookController-->>Client: 200 OK (UserBookPageResponse)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ 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. 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)
Other keywords and placeholders
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: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (11)
apis/src/main/kotlin/org/yapp/apis/book/controller/BookController.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/book/controller/BookControllerApi.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/book/service/UserBookService.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/book/usecase/BookUseCase.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/readingrecord/controller/ReadingRecordControllerApi.kt(1 hunks)domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt(1 hunks)domain/src/main/kotlin/org/yapp/domain/userbook/UserBookRepository.kt(1 hunks)infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt(1 hunks)infra/src/main/kotlin/org/yapp/infra/userbook/repository/JpaUserBookQuerydslRepository.kt(1 hunks)infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/JpaUserBookQuerydslRepositoryImpl.kt(3 hunks)infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/UserBookRepositoryImpl.kt(1 hunks)
🔇 Additional comments (16)
apis/src/main/kotlin/org/yapp/apis/readingrecord/controller/ReadingRecordControllerApi.kt (1)
72-72: OpenAPI 문서화 수정이 올바릅니다.응답 스키마를
ReadingRecordResponse::class에서Page::class로 변경한 것이 정확합니다. 실제 메서드 시그니처가ResponseEntity<Page<ReadingRecordResponse>>를 반환하므로, 이 변경으로 OpenAPI 문서와 실제 구현 간의 일관성이 확보되었습니다.infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt (2)
7-7: 적절한 import 추가
jakarta.persistence.Indeximport가 올바르게 추가되었습니다.
15-21: 효율적인 인덱싱 전략 구현사용자별 도서 제목 검색을 위한 인덱스 구성이 적절합니다:
idx_user_books_title: 제목 기반 검색 최적화idx_user_books_user_id_title: 사용자별 제목 검색에 최적화된 복합 인덱스복합 인덱스에서
user_id를 먼저 배치한 것은 선택도가 높은 컬럼을 앞에 두는 모범 사례를 따른 것입니다.domain/src/main/kotlin/org/yapp/domain/userbook/UserBookRepository.kt (1)
20-26: 도메인 인터페이스 올바르게 확장
findUserBooksByDynamicCondition메서드에title파라미터가 적절히 추가되었습니다. nullable 타입으로 선택적 파라미터임을 명확히 하였고, 파라미터 순서도 논리적입니다.infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/UserBookRepositoryImpl.kt (1)
48-57: 레포지토리 구현체 올바르게 업데이트도메인 인터페이스의 변경사항이 구현체에 올바르게 반영되었습니다.
title파라미터가 하위 JPA 레포지토리로 적절히 전달되고 있습니다.apis/src/main/kotlin/org/yapp/apis/book/controller/BookController.kt (2)
66-66: API 파라미터 올바르게 추가선택적
title쿼리 파라미터가 적절히 추가되었습니다.required = false설정으로 하위 호환성을 유지합니다.
70-70: use case로 파라미터 올바르게 전달
title파라미터가 use case 계층으로 올바르게 전달되고 있습니다.infra/src/main/kotlin/org/yapp/infra/userbook/repository/JpaUserBookQuerydslRepository.kt (1)
11-17: Querydsl 레포지토리 타이틀 필터링 구현 확인 완료
findUserBooksByDynamicCondition인터페이스에title파라미터가 추가되었으며, 구현체의titleContains메서드에서
userBook.title.like("%"+it+"%")형태로 올바르게 LIKE 쿼리가 적용된 것을 확인했습니다. 추가 조치 없이 머지 가능합니다.
- infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/JpaUserBookQuerydslRepositoryImpl.kt:
titleContains메서드에서userBook.title.like("%" + it + "%")사용 확인apis/src/main/kotlin/org/yapp/apis/book/usecase/BookUseCase.kt (1)
78-83: LGTM! 제목 필터링 파라미터가 올바르게 추가되었습니다.
title파라미터가 적절하게 nullable String으로 정의되었고, 서비스 레이어로 올바르게 전달되고 있습니다.domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt (1)
44-47: LGTM! 도메인 서비스에서 제목 필터링이 올바르게 구현되었습니다.도메인 레이어에서
title파라미터가 적절하게 추가되었고 레포지토리로 올바르게 전달되고 있습니다.apis/src/main/kotlin/org/yapp/apis/book/controller/BookControllerApi.kt (2)
120-120: API 문서화가 잘 개선되었습니다.제목 검색 기능에 대한 설명이 Operation 어노테이션에 명확하게 추가되어 사용자가 이해하기 쉽게 작성되었습니다.
145-145: 파라미터 문서화가 적절합니다.
title파라미터에 대한 설명이 명확하게 작성되어 API 사용자가 기능을 이해하기 쉽습니다.infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/JpaUserBookQuerydslRepositoryImpl.kt (2)
28-28: title 파라미터가 올바르게 추가되었습니다.메서드 시그니처에
title파라미터가 적절하게 추가되어 다른 레이어와 일관성을 유지하고 있습니다.
35-36: 쿼리 조건이 일관성 있게 적용되었습니다.메인 쿼리와 카운트 쿼리 모두에
titleContains조건이 적절하게 적용되어 페이징 결과의 정확성을 보장합니다.Also applies to: 50-51
apis/src/main/kotlin/org/yapp/apis/book/service/UserBookService.kt (2)
58-61: 서비스 레이어에서 제목 필터링이 올바르게 구현되었습니다.
title파라미터가 적절하게 추가되었고 도메인 서비스로 올바르게 전달되고 있습니다.
69-72: 상태 카운트와 함께 제목 필터링이 일관성 있게 구현되었습니다.
findUserBooksByDynamicConditionWithStatusCounts메서드에서도title파라미터가 올바르게 전달되어 필터링과 상태 카운트 기능이 함께 작동합니다.
| private fun titleContains(title: String?): BooleanExpression? { | ||
| return title?.takeIf { it.isNotBlank() }?.let { | ||
| userBook.title.like("%" + it + "%") | ||
| } | ||
| } |
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.
🧹 Nitpick (assertive)
LIKE 검색 구현이 올바르지만 성능 고려사항이 있습니다.
titleContains 메서드가 적절하게 구현되었고 빈 문자열 처리도 잘 되어 있습니다. 다만 LIKE '%...%' 패턴은 인덱스를 완전히 활용하지 못할 수 있습니다. PR 목표에서 언급한 것처럼 향후 Full-Text Search 구현을 고려해보시기 바랍니다.
private fun titleContains(title: String?): BooleanExpression? {
return title?.takeIf { it.isNotBlank() }?.let {
- userBook.title.like("%" + it + "%")
+ userBook.title.like("%" + it.replace("%", "\\%").replace("_", "\\_") + "%")
}
}추가적으로 특수문자 이스케이핑을 고려해보세요.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private fun titleContains(title: String?): BooleanExpression? { | |
| return title?.takeIf { it.isNotBlank() }?.let { | |
| userBook.title.like("%" + it + "%") | |
| } | |
| } | |
| private fun titleContains(title: String?): BooleanExpression? { | |
| return title?.takeIf { it.isNotBlank() }?.let { | |
| userBook.title.like( | |
| "%" + it.replace("%", "\\%") | |
| .replace("_", "\\_") + "%" | |
| ) | |
| } | |
| } |
🤖 Prompt for AI Agents
In
infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/JpaUserBookQuerydslRepositoryImpl.kt
around lines 76 to 80, the titleContains method uses a LIKE '%...%' pattern
which can degrade performance and does not handle special characters properly.
To fix this, implement escaping for special characters in the input title string
before constructing the LIKE pattern, and consider planning for a future
migration to Full-Text Search for better performance and accuracy.


🔗 관련 이슈
Close [BOOK-190/feat] 내서재에서 도서검색이 가능하도록 기능을 구현합니다. #59
📘 작업 유형
✨ Feature (기능 추가)
🐞 Bugfix (버그 수정)
🔧 Refactor (코드 리팩토링)
⚙️ Chore (환경 설정)
📝 Docs (문서 작성 및 수정)
✅ Test (기능 테스트)
🎨 style (코드 스타일 수정)
📙 작업 내역
도서 동적 검색 시
userId와title을 조건으로 사용함에 따라,(userId, title)복합 B-Tree 인덱스를 추가했습니다.이를 통해 전체 테이블 스캔을 방지하고, 특정 사용자의 도서 내에서만
LIKE검색을 수행하여 1차적으로 성능을 개선합니다.🧪 테스트 내역
브라우저/기기에서 동작 확인
엣지 케이스 테스트 완료
기존 기능 영향 없음
🎨 스크린샷 또는 시연 영상 (선택)
✅ PR 체크리스트
커밋 메시지가 명확합니다
PR 제목이 컨벤션에 맞습니다
관련 이슈 번호를 작성했습니다
기능이 정상적으로 작동합니다
불필요한 코드를 제거했습니다
💬 추가 설명 or 리뷰 포인트 (선택)
MVP 1차 마감 기한을 고려하여, 우선 B-Tree 인덱싱을 통해 1차적으로 검색 성능을 개선했습니다.
현재
LIKE '%...%'검색 방식은 인덱스의 모든 이점을 활용하지 못하는 한계가 명확합니다.따라서 MVP 이후, Full-Text Search(FTS)를 도입하여 검색 기능을 근본적으로 개선할 예정입니다. 이 PR은 그 전 단계의 개선 사항으로 이해해주시면 감사하겠습니다.
리뷰어님께서는 코드 리뷰와 함께,
UserBookEntity에 추가된@Index설정이 DB 스키마에 정상적으로 반영되었는지 확인 부탁드립니다.Summary by CodeRabbit
신규 기능
문서
성능 개선