-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] #145 매칭 후보 조회 로직에 QueryDSL 도입 및 최적화 #146
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
87352e9
[feat] #145 queryDsl 관련 의존성 추가
2hyunjinn 1b901fd
[feat] #145 queryDsl 관련 의존성 추가
2hyunjinn f9a2519
[feat] #145 QuerydslConfig 구현
2hyunjinn 496aa6e
[feat] #145 MatchingRepository 에 queryDSL 도입
2hyunjinn 4a1a2ff
[feat] #145 MatchingRepository 에서 MatchingRepositoryCustom 참조할 수 있도록 추가
2hyunjinn eb8c8cb
[test] #145 매칭 추가하기에서 MatchingRepositoryCustom 참조하도록 변경
2hyunjinn d50c5f2
[refactor] #145 서브쿼리는 서비스 레벨에서 한번만 조회하고, 이후 메인쿼리만 반복 호출할 수 있도록 변경
2hyunjinn 1918e63
[del] #145 불필요한 코드 제거
2hyunjinn 66a3a39
[refactor] #145 EntityManager 제거
2hyunjinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/festimate/team/domain/matching/repository/MatchingRepositoryCustom.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.festimate.team.domain.matching.repository; | ||
|
|
||
| import org.festimate.team.domain.participant.entity.Participant; | ||
| import org.festimate.team.domain.participant.entity.TypeResult; | ||
| import org.festimate.team.domain.user.entity.Gender; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface MatchingRepositoryCustom { | ||
| List<Long> findExcludeIds(Long applicantId); | ||
|
|
||
| List<Participant> findMatchingCandidatesDsl( | ||
| Long applicantId, | ||
| TypeResult typeResult, | ||
| Gender gender, | ||
| Long festivalId, | ||
| Pageable pageable, | ||
| List<Long> excludedIds | ||
| ); | ||
| } |
65 changes: 65 additions & 0 deletions
65
src/main/java/org/festimate/team/domain/matching/repository/MatchingRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package org.festimate.team.domain.matching.repository; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.festimate.team.domain.matching.entity.MatchingStatus; | ||
| import org.festimate.team.domain.matching.entity.QMatching; | ||
| import org.festimate.team.domain.participant.entity.Participant; | ||
| import org.festimate.team.domain.participant.entity.QParticipant; | ||
| import org.festimate.team.domain.participant.entity.TypeResult; | ||
| import org.festimate.team.domain.user.entity.Gender; | ||
| import org.festimate.team.domain.user.entity.QUser; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class MatchingRepositoryImpl implements MatchingRepositoryCustom { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| private final QParticipant p = QParticipant.participant; | ||
| private final QMatching m = QMatching.matching; | ||
| private final QMatching mSub = new QMatching("mSub"); | ||
| private final QUser u = QUser.user; | ||
|
|
||
| @Override | ||
| public List<Long> findExcludeIds(Long applicantId) { | ||
| return queryFactory | ||
| .select(mSub.targetParticipant.participantId) | ||
| .from(mSub) | ||
| .where( | ||
| mSub.applicantParticipant.participantId.eq(applicantId) | ||
| .and(mSub.status.eq(MatchingStatus.COMPLETED)) | ||
| ) | ||
| .fetch(); | ||
| } | ||
2hyunjinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public List<Participant> findMatchingCandidatesDsl( | ||
| Long applicantId, | ||
| TypeResult typeResult, | ||
| Gender gender, | ||
| Long festivalId, | ||
| Pageable pageable, | ||
| List<Long> excludedIds | ||
| ) { | ||
| return queryFactory | ||
| .selectFrom(p) | ||
| .join(p.user, u).fetchJoin() | ||
| .leftJoin(m) | ||
| .on(m.applicantParticipant.eq(p).or(m.targetParticipant.eq(p))) | ||
| .where( | ||
| p.festival.festivalId.eq(festivalId), | ||
| p.typeResult.eq(typeResult), | ||
| u.gender.ne(gender), | ||
| p.participantId.ne(applicantId), | ||
| excludedIds.isEmpty() ? null : p.participantId.notIn(excludedIds) | ||
| ) | ||
| .groupBy(p) | ||
| .orderBy(m.count().asc()) | ||
| .offset(pageable.getOffset()) | ||
| .limit(pageable.getPageSize()) | ||
| .fetch(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/festimate/team/infra/config/QuerydslConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.festimate.team.infra.config; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import jakarta.persistence.EntityManager; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class QuerydslConfig { | ||
| @Bean | ||
| public JPAQueryFactory jpaQueryFactory(EntityManager em) { | ||
| return new JPAQueryFactory(em); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.