diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java b/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java index 67febb3..217c691 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java @@ -45,7 +45,8 @@ public void addInterceptors(final InterceptorRegistry registry) { .addExcludePathPattern("/api/users/refresh/*") .addExcludePathPattern("/api/like/test/clean") .addExcludePathPattern("/api/like/test/count/**") - .addExcludePathPattern("/api/email/*"); + .addExcludePathPattern("/api/email/*") + .addExcludePathPattern("/api/reviews/test/**"); registry .addInterceptor(pathMatcherInterceptor) diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/global/utils/RedisUtils.java b/src/main/java/com/inq/wishhair/wesharewishhair/global/utils/RedisUtils.java index be7bc8b..d7c0718 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/global/utils/RedisUtils.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/global/utils/RedisUtils.java @@ -36,8 +36,9 @@ public void decreaseData(Long key) { } public Optional getData(Long key) { + Long value = redisTemplate.opsForValue().get(String.valueOf(key)); return Optional.ofNullable( - redisTemplate.opsForValue().get(String.valueOf(key)) + value ); } } diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java b/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java index 9f59b60..ff469b2 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java @@ -60,7 +60,7 @@ public LikeReviewResponse checkIsLiking(Long userId, Long reviewId) { public Long getLikeCount(Long reviewId) { return redisUtils.getData(reviewId) - .orElse(updateLikeCountFromRedis(reviewId)); + .orElseGet(() -> updateLikeCountFromRedis(reviewId)); } public List getLikeCounts(List reviewIds) { diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/review/presentation/ReviewQueryTestController.java b/src/main/java/com/inq/wishhair/wesharewishhair/review/presentation/ReviewQueryTestController.java index ba368af..f524082 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/review/presentation/ReviewQueryTestController.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/review/presentation/ReviewQueryTestController.java @@ -3,15 +3,13 @@ import java.util.List; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.inq.wishhair.wesharewishhair.global.dto.response.ResponseWrapper; -import com.inq.wishhair.wesharewishhair.review.application.dto.response.ReviewResponse; -import com.inq.wishhair.wesharewishhair.review.application.dto.response.ReviewResponseAssembler; +import com.inq.wishhair.wesharewishhair.review.application.LikeReviewService; import com.inq.wishhair.wesharewishhair.review.domain.entity.Review; import com.inq.wishhair.wesharewishhair.review.infrastructure.ReviewQueryDslRepository; -import com.inq.wishhair.wesharewishhair.review.infrastructure.ReviewQueryResponse; import lombok.RequiredArgsConstructor; @@ -21,19 +19,19 @@ public class ReviewQueryTestController { private final ReviewQueryDslRepository reviewQueryDslRepository; + private final LikeReviewService likeReviewService; @Transactional(readOnly = true) - public ResponseWrapper withJoin() { - List reviews = reviewQueryDslRepository.joinWithLikeQuery() - .stream() - .map(ReviewQueryResponse::getReview) - .toList(); - return ReviewResponseAssembler.toWrappedReviewResponse(reviews); + @GetMapping("/join") + public void withJoin() { + reviewQueryDslRepository.joinWithLikeQuery(); } @Transactional(readOnly = true) - public ResponseWrapper withoutJoin() { + @GetMapping("/no_join") + public void withoutJoin() { List reviews = reviewQueryDslRepository.noJoinQuery(); - return ReviewResponseAssembler.toWrappedReviewResponse(reviews); + List reviewIds = reviews.stream().map(Review::getId).toList(); + likeReviewService.getLikeCounts(reviewIds); } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index b75eb5f..ff4e3d5 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -5,7 +5,7 @@ server: spring: data: redis: - host: 3.21.14.25 + host: localhost port: 6379 expire-time: 21600000