Skip to content

Commit

Permalink
Merge pull request #419 from SWM-NM/feat/#418
Browse files Browse the repository at this point in the history
➕ [ADD] @manytoone에 대한 지연로딩 적용
  • Loading branch information
aj4941 authored Oct 8, 2023
2 parents 2b311aa + fa1a61c commit 96f2d6d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class AlgorithmProblemList extends BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long algorithmProblemListId;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROBLEM_ID")
private Problem problem;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ALGORITHM_ID")
private Algorithm algorithm;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class TypeProblemList extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long typeProblemListId;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEST_TYPE_ID")
private TestType testType;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROBLEM_ID")
private Problem problem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class AttemptProblem extends BaseEntity {

private String submitCode;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MEMBER_ID")
private Member member;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEST_ID")
private Tests test;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROBLEM_ID")
private Problem problem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import swm_nm.morandi.aop.annotation.Logging;
import swm_nm.morandi.domain.testDuring.dto.TestStatus;
import swm_nm.morandi.domain.testExit.dto.AttemptProblemDto;
import swm_nm.morandi.domain.testInfo.entity.AttemptProblem;
import swm_nm.morandi.domain.testRecord.dto.TestRecordDto;
import swm_nm.morandi.domain.testInfo.entity.Tests;
import swm_nm.morandi.domain.testRecord.mapper.TestRecordMapper;
Expand All @@ -25,12 +26,14 @@ public class LatestTestInfoService {

private final TestRepository testRepository;

private final AttemptProblemRepository attemptProblemRepository;

@Transactional
public List<TestRecordDto> getTestRecordDtosLatest() {
Long memberId = SecurityUtils.getCurrentMemberId();
//페이징하여 최근 4개의 테스트 기록을 가져옴
Pageable pageable = PageRequest.of(0, 4);
List<Tests> recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED,pageable);
List<Tests> recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED, pageable);

//테스트 기록을 받아와서 dto로 변환하면서 getAttemptProblemDtos를 통해 테스트 문제들을 dto로 변환
List<TestRecordDto> testRecordDtos =
Expand All @@ -48,7 +51,8 @@ public List<TestRecordDto> getTestRecordDtosLatest() {
//Test의 AttemptProblems를 LAZY 로딩하여두고, default_batch_fetch_size 를 통해 한번에 가져옴
@Transactional
public List<AttemptProblemDto> getAttemptProblemDtos(Tests test) {
final long[] index = {1};
final long[] index = { 1 };
// after
return test.getAttemptProblems().stream().map(attemptProblem -> {
AttemptProblemDto attemptProblemDto = AttemptProblemDto.getAttemptProblemDto(attemptProblem);
attemptProblemDto.setTestProblemId(index[0]++);
Expand Down

0 comments on commit 96f2d6d

Please sign in to comment.