-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
โฆnventoryResponse DTO๋ก ๋ฐํ๋๊ฒ ์์ [๋ฐํ์]
โฆperties url ์ค์ ๊ด๋ฆฌ [๋ฐํ์]
โฆ@batchsize, Pagination) & ProductRepository ์ฟผ๋ฆฌ ๊ฐ์ [๋ฐํ์](#77)
โฆ, DTO(ProductAllRetrieveDTO) ๋ณํ์ผ๋ก N+1 ๋ฌธ์ ํด๊ฒฐ ๋ฐ ๋์ฉ๋ ๋ฐ์ดํฐ ์ฑ๋ฅ ์ต์ ํ [๋ฐํ์](#77)
โฆageable, ๋จ๊ฑด ์กฐํ, ์์ฑ, ์์ , ์ญ์ , ๊ฒ์ ๊ธฐ๋ฅ ๊ตฌํ [๋ฐํ์](#77)
โฆ์์ฒญ/์๋ต ์ฒ๋ฆฌ์ PaymentService์ composite key๋ฅผ ํ์ฉํ ์์ฝ ์์ ๊ด๋ฆฌ [๋ฐํ์](#78)
โฆ์ปฌ๋ ์ ์ ๋ฐ์ดํธ ๊ฐ์ , ์ด๋ฏธ์ง ์กฐํ ์ต์ ํ) [๋ฐํ์](#82)
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.
confirm
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.
Approve ๐
๐ Related Issue Numbers
close : #48, #49, #61, #62, #71, #77, #78, #81, #82
๐ ๋ฌด์์ ์ํ PR์ธ๊ฐ์?
@Transactional
ํ์ฉํ ๋ฐ์ดํฐ ์ผ๊ด์ฑ ๋ณด์ฅMultipleBagFetchException
ํด๊ฒฐ,version
ํ๋ ์ด๊ธฐํ@BatchSize
์ ์ฉ,Fetch Join
์ ํตํ ๋จ๊ฑด ์กฐํ ์ต์ ํ๐ 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์ ์ ์กProductService
๋ฅผ ํตํด ์ฌ๊ณ ์ฐจ๊ฐ ์ฒ๋ฆฌโ ScheduledThreadPoolExecutor ํ์ฉํ ์ฌ๊ณ ๋ณต๊ตฌ ์์ฝ
โ Spring Batch๋ฅผ ํ์ฉํ ๋์ฉ๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ต์ ํ
ScheduledThreadPoolExecutor
๋ฅผ ์ด์ฉํ์ฌ ๊ฒฐ์ ํ ์ผ์ ์๊ฐ์ด ์ง๋๋ฉด ์๋ ๋ณต๊ตฌ ์์ฝ ์์ ์คํ4๏ธโฃ JWT ํํฐ๋ฅผ ํตํ ์ค์ ๊ด๋ฆฌ ๋ฐ ์ธ์ฆ ์์คํ ๊ฐ์
โ AccessToken๊ณผ RefreshToken ๋ถ๋ฆฌ
JwtFilter
๋ฅผ ํ์ฉํ์ฌ ํน์ ์์ฒญ์ ํด๋ ์์ ๊ฒ์ฆโ JWT ํํฐ ์ ์ฉ ๋ฒ์ ๊ฐ์
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 ๋ฐ ๊ฒฐ์ ์์คํ ์ ์ฑ๋ฅ์ด ๋ํญ ํฅ์๋์์ต๋๋ค! ๐