Skip to content
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

[mainโฌ…๐Ÿš€BE_5]: JPA ์ตœ์ ํ™” | Fetch Join ๊ธฐ๋ฐ˜ Product ๋‹จ๊ฑด ์กฐํšŒ ๋ฐ ์—…๋ฐ์ดํŠธ ์„ฑ๋Šฅ ๊ฐœ์„  | Kafka ๊ธฐ๋ฐ˜ ๊ฒฐ์ œ ์ฒ˜๋ฆฌ & JWT ์ธ์ฆ ์‹œ์Šคํ…œ ๊ณ ๋„ํ™” [๋ฐ•ํ•œ์†”] #83

Merged
merged 21 commits into from
Feb 22, 2025

Conversation

pjhcsols
Copy link
Owner

@pjhcsols pjhcsols commented Feb 21, 2025

๐Ÿ“Œ Related Issue Numbers

close : #48, #49, #61, #62, #71, #77, #78, #81, #82


๐Ÿ€ ๋ฌด์—‡์„ ์œ„ํ•œ PR์ธ๊ฐ€์š”?

  • ๊ธฐ๋Šฅ ์ถ”๊ฐ€ : Product ๋‹จ๊ฑด ์กฐํšŒ ๋ฐ ์—…๋ฐ์ดํŠธ ๋กœ์ง ๊ตฌํ˜„
  • ์„ฑ๋Šฅ ์ตœ์ ํ™” : Fetch Join ์ ์šฉ, N+1 ๋ฌธ์ œ ํ•ด๊ฒฐ, ์ปฌ๋ ‰์…˜ ์—…๋ฐ์ดํŠธ ๊ฐœ์„ , ์ด๋ฏธ์ง€ ์กฐํšŒ ์ตœ์ ํ™”
  • ๋ฆฌํŒฉํ† ๋ง : DTO ๋ณ€ํ™˜ ์ตœ์ ํ™”, @Transactional ํ™œ์šฉํ•œ ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ ๋ณด์žฅ
  • ๋ฒ„๊ทธ ์ˆ˜์ • : MultipleBagFetchException ํ•ด๊ฒฐ, version ํ•„๋“œ ์ดˆ๊ธฐํ™”
  • ์ฟผ๋ฆฌ ์„ฑ๋Šฅ ๊ฐœ์„  : @BatchSize ์ ์šฉ, Fetch Join์„ ํ†ตํ•œ ๋‹จ๊ฑด ์กฐํšŒ ์ตœ์ ํ™”
  • ๊ฒฐ์ œ ๋ฐ ์žฌ๊ณ  ๊ด€๋ฆฌ ๋กœ์ง ์ถ”๊ฐ€ : Kafka ๊ธฐ๋ฐ˜ ๊ฒฐ์ œ ์š”์ฒญ ์ฒ˜๋ฆฌ, Spring Batch ํ™œ์šฉ ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ตœ์ ํ™”
  • JWT ํ•„ํ„ฐ๋ฅผ ํ†ตํ•œ ์ค‘์•™ ๊ด€๋ฆฌ ๋ฐ ์ธ์ฆ ์‹œ์Šคํ…œ ๊ฐœ์„ 

๐Ÿš€ Description & ๊ธฐ๋Œ€ ๊ฒฐ๊ณผ


1๏ธโƒฃ ๋‹จ๊ฑด ์กฐํšŒ (getProductDetailsByColor) ๊ฐœ์„ 

โœ… Fetch Join์„ ํ™œ์šฉํ•œ ์ตœ์ ํ™”

  • ๊ธฐ์กด findById(productId) ์‚ฌ์šฉ ์‹œ Lazy Loading์œผ๋กœ ์ธํ•ด N+1 ๋ฌธ์ œ ๋ฐœ์ƒ
  • findByIdWithDetails(productId) ๋ฉ”์„œ๋“œ์—์„œ Fetch Join์„ ์ ์šฉํ•˜์—ฌ ๋‹จ์ผ ์ฟผ๋ฆฌ๋กœ ์ƒํ’ˆ์˜ ์ฃผ์š” ์ •๋ณด๋ฅผ ์กฐํšŒ
  • Product ์—”ํ‹ฐํ‹ฐ์™€ ProductCategory, BrandUser, ProductOptions, ProductSizeOptions, ProductColorOptions์„ Fetch Joinํ•˜์—ฌ ๋ถˆํ•„์š”ํ•œ ์ถ”๊ฐ€ ์ฟผ๋ฆฌ ์ œ๊ฑฐ

โœ… ์ƒ‰์ƒ๋ณ„ ์ด๋ฏธ์ง€ ์กฐํšŒ ์ตœ์ ํ™”

  • ProductColorOption ํ…Œ์ด๋ธ”์—์„œ ๋ณ„๋„ ์ฟผ๋ฆฌ๋กœ ์ƒ‰์ƒ๋ณ„ ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ ๋ฐ ์„œ๋ธŒ ์ด๋ฏธ์ง€ ์กฐํšŒ
  • findProductColorOptionByProductIdAndColor(productId, color) ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํŠน์ • ์ปฌ๋Ÿฌ์˜ ์ด๋ฏธ์ง€ URL๋งŒ ๊ฐ€์ ธ์˜ค๋„๋ก ๊ฐœ์„ 
  • ์ปฌ๋ ‰์…˜ ํ•„๋“œ List<String> productPhotoUrls ๋ฐ List<String> productSubPhotoUrls ์‚ฌ์šฉํ•˜์—ฌ ๋Œ€ํ‘œ ๋ฐ ์„œ๋ธŒ ์ด๋ฏธ์ง€ ๋ถ„๋ฆฌ

โœ… DTO ๋ณ€ํ™˜ ์ตœ์ ํ™”

  • ProductDetailDTO๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ถˆํ•„์š”ํ•œ ์—”ํ‹ฐํ‹ฐ ๋กœ๋”ฉ ์—†์ด ํ•„์š”ํ•œ ์ •๋ณด๋งŒ ๋ฐ˜ํ™˜
  • ProductOptionDTO, ProductSizeOptionDTO, ProductColorOptionDTO, ProductImageDTO ๋“ฑ์„ ํ™œ์šฉํ•˜์—ฌ DTO ๋ณ€ํ™˜ ์ตœ์ ํ™”
  • BrandUserDTO ๋งคํ•‘ ์‹œ Enum ๊ฐ’์„ String์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์‰ฝ๊ฒŒ ์ธ์‹ ๊ฐ€๋Šฅํ•˜๋„๋ก ์ฒ˜๋ฆฌ

2๏ธโƒฃ ์—…๋ฐ์ดํŠธ (updateProduct) ๋กœ์ง ๊ฐœ์„ 

โœ… ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ (@Transactional)

  • updateProduct(Long productId, ProductUpdateRequest updateRequest) ๋ฉ”์„œ๋“œ์—์„œ @Transactional์„ ์ ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ ๋ณด์žฅ

โœ… Fetch Join์„ ํ†ตํ•œ ์—ฐ๊ด€ ๋ฐ์ดํ„ฐ ์กฐํšŒ

  • ๊ธฐ์กด findById(productId)๋กœ ์กฐํšŒํ•  ๊ฒฝ์šฐ ์—ฐ๊ด€ ๋ฐ์ดํ„ฐ ์ ‘๊ทผ ์‹œ ์ถ”๊ฐ€์ ์ธ Lazy Loading ๋ฐœ์ƒ
  • findByIdWithDetails(productId)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•œ ๋ฒˆ์˜ ์ฟผ๋ฆฌ๋กœ Product ๋ฐ ์—ฐ๊ด€ ๋ฐ์ดํ„ฐ ์กฐํšŒ

โœ… Selective Update ์ ์šฉ (Optional<T> ํ™œ์šฉ)

  • Optional<T>๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ€๊ฒฝ๋œ ํ•„๋“œ๋งŒ ์—…๋ฐ์ดํŠธ๋˜๋„๋ก ๊ฐœ์„ 
  • productCategory, productName, productPrice, productMaterial, productDesc ๋“ฑ์˜ ํ•„๋“œ๋Š” Optional์„ ํ™œ์šฉํ•˜์—ฌ null ์ฒดํฌ ํ›„ ์—…๋ฐ์ดํŠธ
  • ๋ถˆํ•„์š”ํ•œ null ์—…๋ฐ์ดํŠธ ๋ฐฉ์ง€

โœ… ์ปฌ๋ ‰์…˜ ์—…๋ฐ์ดํŠธ ์ตœ์ ํ™” (updateCollection ๋ฉ”์„œ๋“œ ๋„์ž…)

  • ๊ธฐ์กด ์ปฌ๋ ‰์…˜์„ findFirst().ifPresentOrElse()๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์—…๋ฐ์ดํŠธํ• ์ง€, ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ• ์ง€ ๊ฒฐ์ •
  • productOptions, productSizeOptions, productColorOptions ์—…๋ฐ์ดํŠธ ๋กœ์ง์„ updateCollection ๋ฉ”์„œ๋“œ๋กœ ํ†ตํ•ฉํ•˜์—ฌ ์ฝ”๋“œ ์žฌ์‚ฌ์šฉ์„ฑ ๋ฐ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ

โœ… ์ด๋ฏธ์ง€ ์—…๋ฐ์ดํŠธ ๋กœ์ง ๊ฐœ์„ 

  • ProductColorOption.updateFrom(ProductColorOptionDTO colorUpdate) ๋ฉ”์„œ๋“œ์—์„œ productPhotoUrls ๋ฐ productSubPhotoUrls๋ฅผ ๋ฐฉ์–ด์  ๋ณต์‚ฌํ•˜์—ฌ null ๊ฐ’ ๋ฐฉ์ง€
  • new ArrayList<>(colorUpdate.getProductPhotoUrls())๋ฅผ ํ†ตํ•ด ๋นˆ ๋ฆฌ์ŠคํŠธ๋ผ๋„ ํ• ๋‹นํ•˜์—ฌ NullPointerException ์˜ˆ๋ฐฉ

3๏ธโƒฃ ๊ฒฐ์ œ ๋ฐ ์žฌ๊ณ  ๊ด€๋ฆฌ ๋กœ์ง ์ถ”๊ฐ€

โœ… Kafka ๊ธฐ๋ฐ˜ ๊ฒฐ์ œ ์š”์ฒญ ์ฒ˜๋ฆฌ

  • ๊ฒฐ์ œ ์š”์ฒญ ์‹œ PaymentUpdateMessage๋ฅผ Kafka์— ์ „์†ก
  • Kafka Consumer์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜์—ฌ ProductService๋ฅผ ํ†ตํ•ด ์žฌ๊ณ  ์ฐจ๊ฐ ์ฒ˜๋ฆฌ

โœ… ScheduledThreadPoolExecutor ํ™œ์šฉํ•œ ์žฌ๊ณ  ๋ณต๊ตฌ ์˜ˆ์•ฝ

  • ๊ฒฐ์ œ ์š”์ฒญ์ด ์‹คํŒจํ•˜๊ฑฐ๋‚˜ 10๋ถ„ ๋™์•ˆ ์‘๋‹ต์ด ์—†์œผ๋ฉด ์ž๋™์œผ๋กœ ์žฌ๊ณ ๋ฅผ ๋ณต๊ตฌํ•˜๋Š” ์˜ˆ์•ฝ ์ž‘์—… ์‹คํ–‰

โœ… Spring Batch๋ฅผ ํ™œ์šฉํ•œ ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์ตœ์ ํ™”

  • ScheduledThreadPoolExecutor๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฒฐ์ œ ํ›„ ์ผ์ • ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ์ž๋™ ๋ณต๊ตฌ ์˜ˆ์•ฝ ์ž‘์—… ์‹คํ–‰
  • ๊ฒฐ์ œ ์‹คํŒจ ๋˜๋Š” ์‹œ๊ฐ„ ์ดˆ๊ณผ ์‹œ ์žฌ๊ณ ๋ฅผ ์›๋ž˜ ์ƒํƒœ๋กœ ๋ณต๊ตฌ

4๏ธโƒฃ JWT ํ•„ํ„ฐ๋ฅผ ํ†ตํ•œ ์ค‘์•™ ๊ด€๋ฆฌ ๋ฐ ์ธ์ฆ ์‹œ์Šคํ…œ ๊ฐœ์„ 

โœ… AccessToken๊ณผ RefreshToken ๋ถ„๋ฆฌ

  • JwtFilter๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํŠน์ • ์š”์ฒญ์˜ ํด๋ ˆ์ž„์„ ๊ฒ€์ฆ
  • ํŠน์ • ํด๋ ˆ์ž„์ด ์—†์œผ๋ฉด ๊ถŒํ•œ ์—†์Œ(403 Forbidden) ์ฒ˜๋ฆฌ

โœ… JWT ํ•„ํ„ฐ ์ ์šฉ ๋ฒ”์œ„ ๊ฐœ์„ 

  • ์ธ์ฆ์ด ํ•„์š”ํ•œ API ์š”์ฒญ๋งŒ JwtFilter๋ฅผ ๊ฑฐ์น˜๋„๋ก ์ตœ์ ํ™”
  • ๋ถˆํ•„์š”ํ•œ JwtFilter ์‹คํ–‰์„ ์ค„์—ฌ ์„ฑ๋Šฅ ์ตœ์ ํ™”

๐Ÿ“ข Notes ๋…ผ์˜ํ•˜๊ณ  ์‹ถ์€ ๋‚ด์šฉ

  • @EntityGraph์™€ Fetch Join์˜ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„ ๊ณ ๋ ค ํ•„์š”
  • Spring Data JPA Projections ํ™œ์šฉํ•˜์—ฌ DTO ๋ณ€ํ™˜ ์ตœ์ ํ™” ๊ฐ€๋Šฅ์„ฑ ๊ฒ€ํ† 
  • Querydsl ๋„์ž…์„ ํ†ตํ•œ ๋ณต์žกํ•œ ์กฐํšŒ ์ฟผ๋ฆฌ ์ตœ์ ํ™” ๋ฐฉ์•ˆ ๊ณ ๋ ค

๐Ÿ“ธ Screenshot


โœ… ์ตœ์ ํ™”๋œ ๋‹จ๊ฑด ์กฐํšŒ ๋ฐ ์—…๋ฐ์ดํŠธ ๋กœ์ง ์ ์šฉ
โœ… ์ฟผ๋ฆฌ ์ˆ˜ ๊ฐ์†Œ ๋ฐ ์„ฑ๋Šฅ ํ–ฅ์ƒ (Fetch Join ์ ์šฉ, N+1 ๋ฌธ์ œ ํ•ด๊ฒฐ)
โœ… ์ปฌ๋ ‰์…˜ ์—…๋ฐ์ดํŠธ ๋กœ์ง ๊ฐœ์„  ๋ฐ ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ ๋ณด์žฅ (@Transactional ์ ์šฉ)
โœ… ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ์กฐํšŒ ์ตœ์ ํ™” (ํ•„์š”ํ•œ ์ปฌ๋Ÿฌ์˜ ์ด๋ฏธ์ง€ URL๋งŒ ์กฐํšŒ)
โœ… Kafka ๊ธฐ๋ฐ˜ ๊ฒฐ์ œ ์ฒ˜๋ฆฌ ๋ฐ Spring Batch ํ™œ์šฉํ•œ ์žฌ๊ณ  ๋ณต๊ตฌ ๋กœ์ง ์ถ”๊ฐ€
โœ… JWT ๊ธฐ๋ฐ˜ ์ธ์ฆ ํ•„ํ„ฐ ์ตœ์ ํ™” ๋ฐ ์ค‘์•™ ๊ด€๋ฆฌ ๊ฐœ์„ 

๐Ÿš€ ์ด์ œ Product ๋‹จ๊ฑด ์กฐํšŒ ๋ฐ ์—…๋ฐ์ดํŠธ API ๋ฐ ๊ฒฐ์ œ ์‹œ์Šคํ…œ์˜ ์„ฑ๋Šฅ์ด ๋Œ€ํญ ํ–ฅ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค! ๐Ÿš€

pjhcsols added 21 commits June 9, 2024 13:35
โ€ฆnventoryResponse DTO๋กœ ๋ฐ˜ํ™˜๋˜๊ฒŒ ์ˆ˜์ •[๋ฐ•ํ•œ์†”]
โ€ฆ, DTO(ProductAllRetrieveDTO) ๋ณ€ํ™˜์œผ๋กœ N+1 ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ฐ ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์„ฑ๋Šฅ ์ตœ์ ํ™” [๋ฐ•ํ•œ์†”](#77)
โ€ฆageable, ๋‹จ๊ฑด ์กฐํšŒ, ์ƒ์„ฑ, ์ˆ˜์ •, ์‚ญ์ œ, ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ ๊ตฌํ˜„ [๋ฐ•ํ•œ์†”](#77)
โ€ฆ์ปฌ๋ ‰์…˜ ์—…๋ฐ์ดํŠธ ๊ฐœ์„ , ์ด๋ฏธ์ง€ ์กฐํšŒ ์ตœ์ ํ™”) [๋ฐ•ํ•œ์†”](#82)
Copy link
Collaborator

@seahkeem seahkeem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ปจํŽŒ์ด์šฅ!

Copy link
Collaborator

@xz0112 xz0112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirm

Copy link
Collaborator

@Sunja-An Sunja-An left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve ๐Ÿ‘

@pjhcsols pjhcsols merged commit d67ca44 into main Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์ถ”๊ฐ€ Refactor ์ฝ”๋“œ๋ฆฌํŒฉํ† ๋ง Status:Mergeable ๋ณ‘ํ•ฉ๊ฐ€๋Šฅ์ƒํƒœ
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BE_5] ๋„๋ฉ”์ธํ˜• ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ตฌ์กฐ ๋ณ€๊ฒฝ [BE_5] JwtProperties ์ค‘์•™ ๊ด€๋ฆฌ & JwtFilter๋ฅผ ํ†ตํ•œ ํ† ํฐ ๊ฒ€์ฆ & ์—‘์„ธ์Šค, ๋ฆฌํ”„๋ ˆ์‰ฌ ๊ธฐ๋Šฅ ๋ถ„๋ฆฌ & User๋ณ„ JPA Generic ๋ ˆํฌ ๋ณ€๊ฒฝ [BE_5]์ผ๊ด„์ฒ˜๋ฆฌ์ž‘์—… ์ฝ”๋“œ Logger ์‚ฌ์šฉ & ConfigurationProperties๋ฅผ ์ด์šฉํ•œ ImageProperties url ์ค‘์•™ ๊ด€๋ฆฌ [BE_5][BE_4] KafkaMQ ์ฑ„ํƒ์œผ๋กœ ์ธํ•œ RabbitMQ ์ฃผ์„ ์ฒ˜๋ฆฌ [BE_5][BE_4] ๊ฒฐ์ œ & ์‹ค์‹œ๊ฐ„ ์žฌ๊ณ  ๋ณ€๋™ ์‹œ ๋ฐ์ดํ„ฐ ๋ฉ”์‹œ์ง€ ์ „์†ก์šฉ(SSE) ๊ตฌํ˜„
4 participants