Skip to content

Commit

Permalink
fix: 사진 업로드 시 save() 대신 saveAll()을 사용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
bflykky committed Aug 18, 2024
1 parent a0701d8 commit fbe63ab
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ public PhotoUploadInfo uploadPhotoList(PhotoUploadRequest request, Member member
long startTime = System.currentTimeMillis();
// 사진 URL 리스트를 기반으로 사진 엔티티를 생성하고 DB에 저장
List<Photo> photoList = request.getPhotoUrlList().stream()
.map(photoUrl -> checkAndSavePhotoInDB(photoUrl, extractPhotoNameFromUrl(photoUrl), shareGroup))
.map(photoUrl -> checkAndCreatePhoto(photoUrl, extractPhotoNameFromUrl(photoUrl), shareGroup))
.toList();
photoRepository.saveAll(photoList);
long finishTime = System.currentTimeMillis();
log.info("저장한 사진 개수: {} 장", photoList.size());
log.info("해당 사진 목록을 DB에 저장하는 데 걸린 시간: {} ms", finishTime - startTime);
Expand All @@ -197,16 +198,18 @@ public PhotoUploadInfo uploadPhotoList(PhotoUploadRequest request, Member member
}

// S3에 객체의 존재 여부 확인 및 DB에 사진을 저장하고 객체를 반환하는 메서드
private Photo checkAndSavePhotoInDB(String photoUrl, String photoName, ShareGroup shareGroup) {
// private Photo checkAndSavePhotoInDB(String photoUrl, String photoName, ShareGroup shareGroup) {
private Photo checkAndCreatePhoto(String photoUrl, String photoName, ShareGroup shareGroup) {
long startTime = System.currentTimeMillis();
if (!amazonS3.doesObjectExist(BUCKET_NAME, RAW_PATH_PREFIX + "/" + photoName)) {
throw new BusinessException(PHOTO_NOT_FOUND_S3);
}
long finishTime = System.currentTimeMillis();
log.info("amazonS3.doesObjectExists() 수행 시간: {} ms", finishTime - startTime);

Photo photo = photoConverter.toEntity(photoUrl, photoName, shareGroup);
return photoRepository.save(photo); // 저장된 Photo 객체 반환
return photoConverter.toEntity(photoUrl, photoName, shareGroup);
// Photo photo = photoConverter.toEntity(photoUrl, photoName, shareGroup);
// return photoRepository.save(photo); // 저장된 Photo 객체 반환
}

// 사진 URL에서 사진 이름을 추출하는 메서드
Expand Down

0 comments on commit fbe63ab

Please sign in to comment.