diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index bb7e941..06aebf4 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -26,6 +26,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -44,6 +45,7 @@ @RestController @RequestMapping("/photos") +@Slf4j @RequiredArgsConstructor @Tag(name = "03. 사진 관련 API", description = "사진 업로드, 조회, 삭제, 다운로드를 처리하는 API입니다.") public class PhotoController { @@ -56,7 +58,10 @@ public class PhotoController { @Operation(summary = "Presigned URL 요청 API", description = "Presigned URL을 요청하는 API입니다.") public ResultResponse getPreSignedUrlList(@Valid @RequestBody PreSignedUrlRequest request, @LoginMember Member member) { + long startTime = System.currentTimeMillis(); List preSignedUrlList = photoService.getPreSignedUrlList(request, member); + long finishTime = System.currentTimeMillis(); + log.info("PhotoServiceImpl.getPreSignedUrlList() 수행 시간: {} ms", finishTime - startTime); return ResultResponse.of(CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); } @@ -71,7 +76,10 @@ public ResultResponse uploadSamplePhotoList(@Valid @Reque @Operation(summary = "사진 업로드 API", description = "Presigned URL을 통해 업로드한 사진을 데이터베이스에 저장하는 API입니다.") public ResultResponse uploadPhotoList(@Valid @RequestBody PhotoUploadRequest request, @LoginMember Member member) { + long startTime = System.currentTimeMillis(); PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request, member); + long finishTime = System.currentTimeMillis(); + log.info("PhotoServiceImpl.uploadPhotoList() 수행 시간: {} ms", finishTime - startTime); return ResultResponse.of(UPLOAD_PHOTO, photoUploadInfo); } @@ -131,7 +139,10 @@ public ResultResponse getEtcPhotoListByShareGroup(@RequestParam public ResultResponse getPhotoDownloadUrlList(@RequestParam List photoIdList, @RequestParam Long shareGroupId, @LoginMember Member member) { + long startTime = System.currentTimeMillis(); PhotoDownloadUrlListInfo photoDownloadUrlList = photoService.getPhotoDownloadUrlList(photoIdList, shareGroupId, member); + long finishTime = System.currentTimeMillis(); + log.info("PhotoServiceImpl.getPhotoDownloadUrlList() 수행 시간: {} ms", finishTime - startTime); return ResultResponse.of(DOWNLOAD_PHOTO, photoDownloadUrlList); } @@ -144,7 +155,10 @@ public ResultResponse getPhotoDownloadUrlList(@Request public ResultResponse getPhotoDownloadUrlListByProfile(@RequestParam Long shareGroupId, @RequestParam Long profileId, @LoginMember Member member) { + long startTime = System.currentTimeMillis(); PhotoResponse.PhotoDownloadUrlListInfo photoDownloadUrlList = photoService.getPhotoDownloadUrlListByProfile(shareGroupId, profileId, member); + long finishTime = System.currentTimeMillis(); + log.info("PhotoServiceImpl.getPhotoDownloadUrlListByProfile() 수행 시간: {} ms", finishTime - startTime); return ResultResponse.of(DOWNLOAD_PHOTO, photoDownloadUrlList); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 1fa0ebf..fe5c0ba 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -28,6 +28,7 @@ import com.umc.naoman.global.error.BusinessException; import io.awspring.cloud.s3.S3Template; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -46,6 +47,7 @@ @Service @Transactional(readOnly = true) +@Slf4j @RequiredArgsConstructor public class PhotoServiceImpl implements PhotoService { private final ShareGroupService shareGroupService; @@ -146,6 +148,18 @@ private SamplePhoto checkAndSaveSamplePhotoInDB(String photoUrl, String photoNam return samplePhotoRepository.save(samplePhoto); } + /** + * 공유 그룹과 프로필을 검증 - select 쿼리 2 + * 공유 그룹 get - 1차 캐시에서 가져옴. 쿼리 0 + * S3에 사진이 있는지 검증 - 쿼리는 안나가지만, 시간이 소요됨 + * Photo 엔티티 생성 수 save - 사진 개수만큼 쿼리 n + * ElasticSearch에 photos_es 벌크 insert - 쿼리 1(또는 0) + * 해당 공유 그룹의 프로필 목록 조회 - select 쿼리 1 + * + * @param request + * @param member + * @return + */ @Override @Transactional public PhotoUploadInfo uploadPhotoList(PhotoUploadRequest request, Member member) { @@ -179,9 +193,12 @@ public PhotoUploadInfo uploadPhotoList(PhotoUploadRequest request, Member member // S3에 객체의 존재 여부 확인 및 DB에 사진을 저장하고 객체를 반환하는 메서드 private Photo checkAndSavePhotoInDB(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 객체 반환