Skip to content
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

[FEAT] 성능 이슈가 의심되는 특정 API에 대한 수행 시간 로깅 추가 #125

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,7 @@

@RestController
@RequestMapping("/photos")
@Slf4j
@RequiredArgsConstructor
@Tag(name = "03. 사진 관련 API", description = "사진 업로드, 조회, 삭제, 다운로드를 처리하는 API입니다.")
public class PhotoController {
Expand All @@ -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));
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,7 @@

@Service
@Transactional(readOnly = true)
@Slf4j
@RequiredArgsConstructor
public class PhotoServiceImpl implements PhotoService {
private final ShareGroupService shareGroupService;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 객체 반환
Expand Down