-
Notifications
You must be signed in to change notification settings - Fork 0
[hotfix] 책 저장시 3000자 넘을경우 ... 처리 추가해서 db 저장하도록 수정 #328
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
WalkthroughNaver 책 XML 파서에서 description을 HTML 언이스케이프한 뒤 길이를 확인해 3000자를 초과하면 잘라서 "..."를 덧붙여 반환하도록 변경했습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant XML as Naver API XML
participant Parser as NaverBookXmlParser
participant DB as Database
XML->>Parser: 책 데이터(XML) 전달
Parser->>Parser: title, author 등 파싱
Parser->>Parser: rawDescription = unescape(htmlDescription)
alt rawDescription.length > MAX_DESCRIPTION_LENGTH
note right of Parser #f9f0c1: 잘라서 말줄임표 추가\n(truncate + "...")
Parser->>DB: 저장할 description = truncated + "..."
else rawDescription.length <= MAX_DESCRIPTION_LENGTH
Parser->>DB: 저장할 description = rawDescription
end
Parser->>DB: 나머지 필드와 함께 저장 요청
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 분 Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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. Comment |
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
🧹 Nitpick comments (1)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java (1)
74-74: 매직 넘버를 상수로 추출하는 것을 고려하세요.3000이라는 값이 하드코딩되어 있습니다. 이 값이 데이터베이스 컬럼 제약과 연관된 경우, 클래스 레벨이나 설정 파일의 상수로 정의하면 유지보수성이 향상됩니다.
예시:
public class NaverBookXmlParser { + private static final int MAX_DESCRIPTION_LENGTH = 3000; public static NaverBookParseResult parseBookList(String xml) { ... } public static NaverDetailBookParseResult parseBookDetail(String xml) { ... String rawDescription = StringEscapeUtils.unescapeHtml4(getTagValue(item, "description")); String description; String suffix = "..."; - if (rawDescription.length() > 3000) { - description = rawDescription.substring(0, 3000 - suffix.length()) + suffix; + if (rawDescription.length() > MAX_DESCRIPTION_LENGTH) { + description = rawDescription.substring(0, MAX_DESCRIPTION_LENGTH - suffix.length()) + suffix; } else { description = rawDescription; } ... }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java (2)
71-78: 데이터베이스 컬럼 정의 확인 결과 및 검토의견 재평가검증 결과,
BookJpaEntity의description필드는@Column(length = 3000)으로 정의되어 있으며, 이는 문자 단위 제한입니다. 현재 코드는 3000자 초과 시 2997자로 절단하고 "..."을 추가합니다.검토의견의 기술적 유효성:
- Java의
String.substring()은 UTF-16 코드 유닛 단위로 작동하므로, 이론적으로 서로게이트 페어 분할 위험이 존재합니다.실제 적용 맥락 분석:
- 네이버 도서 API 응답: 한국 도서 설명 (한글, 영문 포함)
- 한글 문자: U+AC00~U+D7A3 범위 (모두 BMP 내, 서로게이트 페어 없음)
- 이모지 포함 가능성: 극히 낮음 (도서 설명에 이모지 사용 드문)
결론:
원본 검토 의견은 기술적으로 유효하나, 한국 도서 설명에 대해서는 실제 발생 가능성이 매우 낮습니다. 현재 코드는 한글, 영문, 대부분의 공통 유니코드 범위에서 안전합니다.이모지 또는 비-BMP 문자를 지원해야 할 필요가 생기면
Character.codePointCount()/offsetByCodePoints()사용으로 개선할 수 있습니다. 현 단계에서는 코드 작동에 문제가 없습니다.
74-74: 검토 의견이 부정확합니다. 데이터베이스 컬럼이 바이트 단위가 아닌 문자 단위로 제약되어 있습니다.BookJpaEntity.java의 description 필드는
@Column(length = 3000)으로 정의되어 있습니다. JPA의 length 속성은 문자 단위이며, 현대의 MySQL VARCHAR도 문자 단위로 길이를 제한합니다. 따라서 코드의String.length() > 3000체크는 데이터베이스 컬럼 제약과 완벽하게 일치합니다. UTF-8mb4 인코딩도 이를 변경하지 않습니다.Likely an incorrect or invalid review comment.
Test Results486 tests 486 ✅ 47s ⏱️ Results for commit 7632374. ♻️ This comment has been updated with latest results. |
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
🧹 Nitpick comments (1)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java (1)
74-74: 선택적 개선: 접미사를 상수로 정의하면 유지보수성이 향상됩니다."..." 문자열을 인라인으로 사용하는 대신 클래스 상수로 정의하면 향후 변경이나 재사용이 용이합니다.
다음 diff를 적용하여 접미사를 상수로 추출하세요:
public class NaverBookXmlParser { private static final int MAX_DESCRIPTION_LENGTH = 3000; + private static final String TRUNCATION_SUFFIX = "..."; public static NaverBookParseResult parseBookList(String xml) {그리고 사용 부분을 수정하세요:
String rawDescription = StringEscapeUtils.unescapeHtml4(getTagValue(item, "description")); String description; - String suffix = "..."; - if (rawDescription.length() > MAX_DESCRIPTION_LENGTH) { - description = rawDescription.substring(0, MAX_DESCRIPTION_LENGTH - suffix.length()) + suffix; + if (rawDescription.length() > MAX_DESCRIPTION_LENGTH) { + description = rawDescription.substring(0, MAX_DESCRIPTION_LENGTH - TRUNCATION_SUFFIX.length()) + TRUNCATION_SUFFIX; } else { description = rawDescription; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java(2 hunks)
🔇 Additional comments (3)
src/main/java/konkuk/thip/book/adapter/out/api/naver/NaverBookXmlParser.java (3)
19-19: 구현 로직이 정확합니다.HTML 언이스케이프 후 문자 길이를 확인하고 3000자를 초과하면 2997자로 자르고 "..."를 추가하는 로직이 올바르게 구현되었습니다. 최종적으로 정확히 3000자가 되도록 처리되며, NPE 위험도 없습니다.
Also applies to: 72-79
72-79: 데이터베이스 스키마 검증 결과: 원래 리뷰 코멘트의 우려는 근거가 없습니다.코드베이스 확인 결과:
BookJpaEntity.java39번 줄:@Column(length = 3000)정의- JPA/Hibernate의
@Column(length=N)은 기본적으로 문자 단위의 길이를 나타냅니다- 코드의
String.length()는 문자 수를 반환하며, 이는 데이터베이스 컬럼 정의와 일치합니다- 이는 표준 JPA/Hibernate 동작이며, MySQL, PostgreSQL, Oracle 등 대부분의 데이터베이스에서 문자 기반으로 동작합니다
따라서 현재 코드의 문자 기반 길이 제한은 데이터베이스 스키마와 올바르게 정렬되어 있습니다. 바이트 기반 VARCHAR 설정(예: Oracle
VARCHAR(3000) BYTE)은 적용되지 않습니다.Likely an incorrect or invalid review comment.
67-71: 제목, ISBN을 제외한 author, publisher 필드에만 길이 제한 필요코드베이스를 검토한 결과,
title과isbn은 이미 BookJpaEntity에서 길이 제약이 설정되어 있습니다 (각각 100, 13). 하지만authorName과publisher필드는 @column 어노테이션이 없어 길이 제한이 없으며, 이 필드들이 Naver API로부터 직접 전달되어 데이터베이스에 저장될 때 제약 위반이 발생할 수 있습니다.특히
description이 이미 파서 단계에서 3000자로 절단되는 패턴을 따르고 있으므로,authorName과publisher도 동일한 방식으로 길이 제한을 적용하거나 절단 처리가 필요한지 검토해 주세요. 또한 HTML 언이스케이프는 일반적으로 문자열을 단축시키므로 (예: "<" → "<"), 이 부분은 추가 고려가 필요하지 않습니다.
seongjunnoh
left a comment
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.
수정하신 부분 확인했습니다! 기존에 관련 테스트 코드가 없어서 실제 데이터로 확인해주셨군요
| if (rawDescription.length() > MAX_DESCRIPTION_LENGTH) { | ||
| description = rawDescription.substring(0, MAX_DESCRIPTION_LENGTH - suffix.length()) + suffix; | ||
| } else { | ||
| description = rawDescription; | ||
| } |
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.
확인했습니다!!
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.
확인했슴다~
buzz0331
left a comment
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.
늦어서 죄송합니다 🙏🏻 확인했습니다~
범망경보살계본사기 좀 무섭네여
| if (rawDescription.length() > MAX_DESCRIPTION_LENGTH) { | ||
| description = rawDescription.substring(0, MAX_DESCRIPTION_LENGTH - suffix.length()) + suffix; | ||
| } else { | ||
| description = rawDescription; | ||
| } |
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.
확인했슴다~
| String description = StringEscapeUtils.unescapeHtml4(getTagValue(item, "description")); | ||
| String rawDescription = StringEscapeUtils.unescapeHtml4(getTagValue(item, "description")); | ||
| String description; | ||
| String suffix = "..."; |
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.
p3: 이것도 static final로 빼도 되지 않을까여??
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.
옷 넵!!
#️⃣ 연관된 이슈
📝 작업 내용
📸 스크린샷
💬 리뷰 요구사항
📌 PR 진행 시 이러한 점들을 참고해 주세요
Summary by CodeRabbit