Skip to content

Commit

Permalink
Merge pull request #125 from Na-o-man/feature/#124/logging
Browse files Browse the repository at this point in the history
[FEAT] 성능 이슈가 의심되는 특정 API에 대한 수행 시간 로깅 추가
bflykky authored Aug 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents b6cada9 + 0ce336d commit 23d8aa1
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<PreSignedUrlListInfo> getPreSignedUrlList(@Valid @RequestBody PreSignedUrlRequest request,
@LoginMember Member member) {
long startTime = System.currentTimeMillis();
List<PreSignedUrlInfo> 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<SamplePhotoUploadInfo> uploadSamplePhotoList(@Valid @Reque
@Operation(summary = "사진 업로드 API", description = "Presigned URL을 통해 업로드한 사진을 데이터베이스에 저장하는 API입니다.")
public ResultResponse<PhotoUploadInfo> 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<PagedPhotoInfo> getEtcPhotoListByShareGroup(@RequestParam
public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@RequestParam List<Long> 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<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@Request
public ResultResponse<PhotoDownloadUrlListInfo> 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);
}

Original file line number Diff line number Diff line change
@@ -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 객체 반환

0 comments on commit 23d8aa1

Please sign in to comment.