🔨 Refactor: 이미지 파일 도메인 처리 구조 개선#154
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces pet profile image management, allowing users to register and update pet profile image URLs. It adds exception handling for the image file domain, implements image saving and updating logic in ImageFileServiceImpl, and integrates these changes into the pet registration and update flows. The review feedback highlights a compilation error in ImageFileServiceImpl due to an incorrect lambda signature in ThrowingFunction.of. Additionally, it suggests removing @Transactional from the image upload method to prevent database connection pool exhaustion during external network I/O, and recommends using Spring Data JPA instead of introducing a new MyBatis mapper to update ImageFile entities.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @Transactional(readOnly = true) | ||
| @Override |
There was a problem hiding this comment.
uploadImages 메서드는 데이터베이스와 상호작용하지 않고 외부 서비스(Cloudinary)로의 네트워크 I/O 작업만 수행합니다. 느린 외부 네트워크 호출 동안 데이터베이스 트랜잭션(@Transactional)을 유지하면 커넥션 풀의 커넥션을 불필요하게 오래 점유하게 되어, 트래픽이 몰릴 때 커넥션 풀 고갈(Connection Pool Exhaustion) 문제를 유발할 수 있습니다. 이 메서드에서 @Transactional(readOnly = true) 어노테이션을 제거하는 것을 권장합니다.
| @Transactional(readOnly = true) | |
| @Override | |
| @Override |
| int updatedRows = imageFileMapper.updatePetProfileImage( | ||
| pet.getPetId(), | ||
| imageFileUrl, | ||
| extractOriginalFilename(imageFileUrl) | ||
| ); | ||
|
|
||
| if (updatedRows == 0) { | ||
| savePetProfileImage(pet, imageFileUrl); | ||
| } |
There was a problem hiding this comment.
JPA로 관리되는 ImageFile 엔티티를 업데이트하기 위해 새로운 MyBatis Mapper(ImageFileMapper)를 도입하는 것은 불필요한 복잡성을 초래하며, JPA 영속성 컨텍스트(1차 캐시)와 데이터베이스 상태 간의 불일치 문제를 발생시킬 수 있습니다.
MyBatis를 사용하는 대신 Spring Data JPA를 활용하여 일관된 데이터 접근 기술을 사용하는 것이 좋습니다. 다음과 같은 방법으로 개선할 수 있습니다:
ImageFileRepository에findByPet_PetId메서드를 정의하여 기존 엔티티를 조회한 후, 엔티티의 필드를 직접 수정하여 JPA의 더티 체킹(Dirty Checking)을 활용합니다.- 또는
ImageFileRepository에@Modifying과@Query를 사용하여 벌크 업데이트 쿼리를 작성합니다.
이렇게 개선하면 추가적인 ImageFileMapper.java 인터페이스와 ImageFileMapper.xml 파일을 완전히 제거할 수 있어 유지보수성이 크게 향상됩니다.
imageFileRepository.findByPet_PetId(pet.getPetId())
.ifPresentOrElse(
imageFile -> {
// TODO: ImageFile 엔티티에 업데이트 메서드 추가 필요
imageFile.updateProfileImage(imageFileUrl, extractOriginalFilename(imageFileUrl));
},
() -> savePetProfileImage(pet, imageFileUrl)
);- 펫 생성 및 수정 시 imageFileUrl 저장/수정 로직을 ImageFileService로 위임 - ImageFileException 및 ImageFileErrorCode 추가로 이미지 파일 전용 예외 처리 분리 - ImageFileMapper를 추가해 프로필 이미지 URL 동적 업데이트 처리 - 이미지 파일 및 펫 서비스 테스트 보강 Closes DoDo-Project#153
83009be to
5109f35
Compare
📄 작업 내용 (Description)
🔗 관련 이슈 (Related Issues)
✅ 체크리스트 (Checklist)
Style)Test)📸 스크린샷 (Screenshots)
💬 기타 사항 (Etc)
펫 생성 api를 사용할때 url이미지가 들어가지 않아서 로직 변경했습니다.