From 947e3820e885fb7569269231d2b72586806261c4 Mon Sep 17 00:00:00 2001 From: fakerdeft Date: Sat, 11 May 2024 22:57:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EC=97=85=EC=9D=98=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=20=EC=A1=B0=ED=9A=8C=20=EC=95=88=20=EB=90=98=EB=8D=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/QuestionServiceImpl.java | 2 - .../QuestionCustomRepositoryImpl.java | 107 +++++------------- 2 files changed, 27 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/coverflow/question/application/QuestionServiceImpl.java b/src/main/java/com/coverflow/question/application/QuestionServiceImpl.java index 3ad7f25e..f1518a4b 100644 --- a/src/main/java/com/coverflow/question/application/QuestionServiceImpl.java +++ b/src/main/java/com/coverflow/question/application/QuestionServiceImpl.java @@ -1,6 +1,5 @@ package com.coverflow.question.application; -import com.coverflow.company.infrastructure.CompanyRepository; import com.coverflow.member.application.MemberServiceImpl; import com.coverflow.question.domain.Question; import com.coverflow.question.dto.AnswerListDTO; @@ -36,7 +35,6 @@ public class QuestionServiceImpl implements QuestionService { private final MemberServiceImpl memberService; private final AnswerServiceImpl answerService; - private final CompanyRepository companyRepository; private final QuestionRepository questionRepository; @Override diff --git a/src/main/java/com/coverflow/question/infrastructure/QuestionCustomRepositoryImpl.java b/src/main/java/com/coverflow/question/infrastructure/QuestionCustomRepositoryImpl.java index e43d4ff5..c51770c4 100644 --- a/src/main/java/com/coverflow/question/infrastructure/QuestionCustomRepositoryImpl.java +++ b/src/main/java/com/coverflow/question/infrastructure/QuestionCustomRepositoryImpl.java @@ -21,8 +21,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import static com.coverflow.question.domain.QQuestion.question; @@ -58,47 +56,21 @@ public Optional> findRegisteredQuestionsById( final long companyId, final String questionTag ) { - List questions; - long total; - - CompletableFuture> questionsFuture = CompletableFuture.supplyAsync(() -> - jpaQueryFactory - .selectFrom(question) - .leftJoin(question.answers).fetchJoin() - .where( - question.company.id.eq(companyId), - question.questionStatus.eq(true), - toContainsQuestionTag(questionTag) - ) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(makeOrderSpecifiers(question, pageable)) - .distinct() - .fetch() - ); - - CompletableFuture countFuture = CompletableFuture.supplyAsync(() -> - jpaQueryFactory - .select(question.count()) - .from(question) - .where( - question.company.id.eq(companyId), - question.questionStatus.eq(true), - toContainsQuestionTag(questionTag) - ) - .fetchOne() - ); - - CompletableFuture.allOf(questionsFuture, countFuture).join(); - - try { - questions = questionsFuture.get(); - total = countFuture.get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - - return Optional.of(new PageImpl<>(questions, pageable, total)); + List questions = jpaQueryFactory + .selectFrom(question) + .leftJoin(question.answers).fetchJoin() + .where( + question.company.id.eq(companyId), + question.questionStatus.eq(true), + toContainsQuestionTag(questionTag) + ) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(makeOrderSpecifiers(question, pageable)) + .distinct() + .fetch(); + + return Optional.of(new PageImpl<>(questions, pageable, questions.size())); } @Override @@ -106,43 +78,18 @@ public Optional> findWithFilters( final Pageable pageable, final FindQuestionAdminRequest request ) { - List questions; - long total; - - CompletableFuture> questionsFuture = CompletableFuture.supplyAsync(() -> - jpaQueryFactory - .selectFrom(question) - .where( - toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()), - eqStatus(request.status()) - ) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(makeOrderSpecifiers(question, pageable)) - .fetch() - ); - - CompletableFuture countFuture = CompletableFuture.supplyAsync(() -> - jpaQueryFactory - .select(question.count()) - .from(question) - .where( - toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()), - eqStatus(request.status()) - ) - .fetchOne() - ); - - CompletableFuture.allOf(questionsFuture, countFuture).join(); - - try { - questions = questionsFuture.get(); - total = countFuture.get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - - return Optional.of(new PageImpl<>(questions, pageable, total)); + List questions = jpaQueryFactory + .selectFrom(question) + .where( + toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()), + eqStatus(request.status()) + ) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(makeOrderSpecifiers(question, pageable)) + .fetch(); + + return Optional.of(new PageImpl<>(questions, pageable, questions.size())); } private BooleanExpression toContainsQuestionTag(final String questionTag) {