Skip to content

Commit

Permalink
feat: 리뷰 쿼리 성능 테스트를 위한 세팅
Browse files Browse the repository at this point in the history
* 조인을 사용하는 쿼리와 사용하지 않는 쿼리
  • Loading branch information
EunChanNam committed Dec 4, 2023
1 parent f03d439 commit 45e9373
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public void decreaseData(Long key) {
}

public Optional<Long> getData(Long key) {
Long value = redisTemplate.opsForValue().get(String.valueOf(key));
return Optional.ofNullable(
redisTemplate.opsForValue().get(String.valueOf(key))
value
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> getLikeCounts(List<Long> reviewIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,19 +19,19 @@
public class ReviewQueryTestController {

private final ReviewQueryDslRepository reviewQueryDslRepository;
private final LikeReviewService likeReviewService;

@Transactional(readOnly = true)
public ResponseWrapper<ReviewResponse> withJoin() {
List<Review> reviews = reviewQueryDslRepository.joinWithLikeQuery()
.stream()
.map(ReviewQueryResponse::getReview)
.toList();
return ReviewResponseAssembler.toWrappedReviewResponse(reviews);
@GetMapping("/join")
public void withJoin() {
reviewQueryDslRepository.joinWithLikeQuery();
}

@Transactional(readOnly = true)
public ResponseWrapper<ReviewResponse> withoutJoin() {
@GetMapping("/no_join")
public void withoutJoin() {
List<Review> reviews = reviewQueryDslRepository.noJoinQuery();
return ReviewResponseAssembler.toWrappedReviewResponse(reviews);
List<Long> reviewIds = reviews.stream().map(Review::getId).toList();
likeReviewService.getLikeCounts(reviewIds);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server:
spring:
data:
redis:
host: 3.21.14.25
host: localhost
port: 6379
expire-time: 21600000

Expand Down

0 comments on commit 45e9373

Please sign in to comment.