-
Notifications
You must be signed in to change notification settings - Fork 1
๐ Fix: 3์ฐจ ์ถ๊ฐ ์์ฒญ์ฌํญ์ ์์ ํ๋ค #164
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
Changes from all commits
e4eaf27
7cd4eb9
8224fc0
91473fa
aadfdb0
1d38cd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,28 @@ | |
| import KUSITMS.WITHUS.domain.recruitment.position.repository.PositionRepository; | ||
| import KUSITMS.WITHUS.domain.recruitment.recruitment.entity.Recruitment; | ||
| import KUSITMS.WITHUS.domain.recruitment.recruitment.repository.RecruitmentRepository; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static KUSITMS.WITHUS.domain.recruitment.recruitment.entity.QRecruitment.recruitment; | ||
| import static KUSITMS.WITHUS.domain.recruitment.recruitmentOrganizationRole.entity.QRecruitmentOrganizationRole.recruitmentOrganizationRole; | ||
| import static KUSITMS.WITHUS.domain.organization.organizationRole.entity.QOrganizationRole.organizationRole; | ||
|
|
||
| import KUSITMS.WITHUS.global.exception.CustomException; | ||
| import KUSITMS.WITHUS.global.exception.ErrorCode; | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| @RequiredArgsConstructor | ||
| public class PositionServiceImpl implements PositionService { | ||
|
|
||
| private final PositionRepository positionRepository; | ||
| private final RecruitmentRepository recruitmentRepository; | ||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| /** | ||
| * ํํธ ์์ฑ | ||
|
|
@@ -53,8 +62,20 @@ public void delete(Long id) { | |
|
|
||
| @Override | ||
| public List<PositionResponseDTO.Detail> findAllByRecruitmentId(Long recruitmentId) { | ||
| return positionRepository.findAllByRecruitmentId(recruitmentId).stream() | ||
| .map(PositionResponseDTO.Detail::from) | ||
| // Recruitment์ RecruitmentOrganizationRole ๋ฆฌ์คํธ์ ๊ฐ๊ฐ์ OrganizationRole์ ํจ๊ป ์กฐํํ๊ธฐ ์ํด fetch join ์ฌ์ฉ | ||
| Recruitment found = queryFactory | ||
| .selectFrom(recruitment) | ||
| .leftJoin(recruitment.positions, recruitmentOrganizationRole).fetchJoin() | ||
| .leftJoin(recruitmentOrganizationRole.organizationRole, organizationRole).fetchJoin() | ||
| .where(recruitment.id.eq(recruitmentId)) | ||
| .fetchOne(); | ||
|
|
||
| if (found == null) { | ||
| throw new CustomException(ErrorCode.RECRUITMENT_NOT_EXIST); | ||
| } | ||
|
|
||
| return found.getPositions().stream() | ||
| .map(ror -> PositionResponseDTO.Detail.from(ror.getOrganizationRole())) | ||
| .toList(); | ||
|
Comment on lines
+65
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 69์์ ๐ null ํํฐ๋ง์ ์ถ๊ฐํ ์์ ์ ์ return found.getPositions().stream()
+ .filter(ror -> ror.getOrganizationRole() != null)
.map(ror -> PositionResponseDTO.Detail.from(ror.getOrganizationRole()))
.toList();๋๋ - .leftJoin(recruitmentOrganizationRole.organizationRole, organizationRole).fetchJoin()
+ .join(recruitmentOrganizationRole.organizationRole, organizationRole).fetchJoin()
๐ค Prompt for AI Agents |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N+1 ์ฟผ๋ฆฌ ๋ฌธ์ ํด๊ฒฐ์ ์ํ fetch join ์ต์ ํ
QueryDSL์ ์ฌ์ฉํ์ฌ ๋ช ์์ ์ผ๋ก fetch join์ ์ํํ๋ ๋ฆฌํฉํ ๋ง์ ๊ถ์ฅ๋ฉ๋๋ค. ์ด๋ฅผ ํตํด
assignments์organizationRole์ ์ง์ฐ ๋ก๋ฉ ์ ๋ฐ์ํ ์ ์๋ N+1 ์ฟผ๋ฆฌ ๋ฌธ์ ๋ฅผ ๋ฐฉ์งํฉ๋๋ค.๊ตฌํ ์์ธ:
Hibernate ๋ฒ์ ๊ณ ๋ ค์ฌํญ:
hibernate.query.passDistinctThrough=falseํํธ ์ฌ์ฉ์ ๊ฒํ ํ์ธ์.๐ค Prompt for AI Agents