Skip to content

Commit

Permalink
chore: Analysis - Ability fetch Type 변경 (LAZY -> EAGER)
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 committed Feb 18, 2025
1 parent c6a820d commit e98a2ff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ public void parseAndSaveAbilities(Map<String, String> keywordList, Analysis anal

Ability ability = AbilityConverter.toAbility(keyword, entry.getValue(), analysis, user);
abilityDbService.saveAbility(ability);
analysis.addAbility(ability);

if (analysis.getAbilityList() != null)
analysis.addAbility(ability);
abilityCount++;
}
validAbilityCount(abilityCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;

import java.util.ArrayList;
import java.util.List;

@Entity
Expand Down Expand Up @@ -37,8 +38,8 @@ public class Analysis extends BaseEntity {
private Record record;

@BatchSize(size = 3)
@OneToMany(mappedBy = "analysis", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Ability> abilityList;
@OneToMany(mappedBy = "analysis", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Ability> abilityList = new ArrayList<>();

public void updateContent(String content) {
if (content != null && !content.isEmpty())
Expand All @@ -52,9 +53,11 @@ public void updateComment(String comment) {
}

public void addAbility(Ability ability) {
if (abilityList == null)
abilityList = new ArrayList<>();

if (ability != null) {
this.abilityList.add(ability);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public void deleteRecordByFolder(Folder folder) {
recordRepository.deleteRecordByFolder(folder);
}

public int getRecordCount(User user) {
return recordRepository.getRecordCount(user);
public int getRecordCount(Long userId) {
return recordRepository.getRecordCount(userId);
}

public int getRecordCountByChatType(Long userId) {
return recordRepository.getRecordCountByType(userId);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import corecord.dev.domain.ability.exception.AbilityException;
import corecord.dev.domain.ability.status.AbilityErrorStatus;
import corecord.dev.domain.analysis.application.AnalysisService;
import corecord.dev.domain.analysis.domain.entity.Analysis;
import corecord.dev.domain.chat.application.ChatDbService;
import corecord.dev.domain.chat.domain.entity.ChatRoom;
import corecord.dev.domain.folder.application.FolderDbService;
Expand Down Expand Up @@ -37,13 +38,13 @@ public class RecordServiceImpl implements RecordService {
private final int listSize = 30;

/**
* user의 MEMO ver. 경험을 기록하고 폴더를 지정한 후 생성된 경험 기록 정보를 반환합니다.
* user의 경험을 기록하고 폴더를 지정한 후 생성된 경험 기록 정보를 반환합니다.
*
* @param userId, recordDto
* @return recordId, title, content, folderName, createdAt
*/
@Override
public RecordResponse.MemoRecordDto createMemoRecord(Long userId, RecordRequest.RecordDto recordDto) {
public RecordResponse.RecordAnalysisDto createRecord(Long userId, RecordRequest.RecordDto recordDto) {
User user = userDbService.findUserById(userId);
String title = recordDto.getTitle();
String content = recordDto.getContent();
Expand All @@ -56,10 +57,12 @@ public RecordResponse.MemoRecordDto createMemoRecord(Long userId, RecordRequest.
Record record = createRecordBasedOnType(recordDto, user, folder);

// 역량 분석 레포트 생성
analysisService.createAnalysis(record, user);
Analysis analysis = analysisService.createAnalysis(record, user);
recordDbService.saveRecord(record);

return RecordConverter.toMemoRecordDto(record);
// Chat 경험 기록 개수 카운트
int chatRecordCount = getChatRecordCount(record, userId);
return RecordConverter.toRecordAnalysisDto(analysis, chatRecordCount);
}

private Record createRecordBasedOnType(RecordRequest.RecordDto recordDto, User user, Folder folder) {
Expand All @@ -70,6 +73,12 @@ private Record createRecordBasedOnType(RecordRequest.RecordDto recordDto, User u
return RecordConverter.toChatRecordEntity(recordDto.getTitle(), recordDto.getContent(), user, folder, chatRoom);
}

private int getChatRecordCount(Record record, Long userId) {
return record.isMemoType()
? 0
: recordDbService.getRecordCountByChatType(userId);
}

/**
* recordId를 받아 MEMO ver. 경험 기록의 상세 정보를 반환합니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ List<Record> findRecordsByKeyword(

@Query("SELECT COUNT(r) " +
"FROM Record r " +
"WHERE r.user = :user " +
"WHERE r.user.userId = :userId " +
"AND r.folder is not null") // 임시 저장 기록 제외
int getRecordCount(@Param(value = "user") User user);
int getRecordCount(@Param(value = "userId") Long userId);

@Query("SELECT COUNT(r) " +
"FROM Record r " +
"WHERE r.user.userId = :userId " +
"AND r.folder is not null " +
"AND r.type = 'CHAT' ")
int getRecordCountByType(@Param(value = "userId") Long userId);

@Modifying
@Query("DELETE " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void registerUser() {
void getUserInfo() {
// Given
when(userDbService.getUser(newUser.getUserId())).thenReturn(newUser);
when(recordDbService.getRecordCount(newUser)).thenReturn(0);
when(recordDbService.getRecordCount(newUser.getUserId())).thenReturn(0);

// When
UserResponse.UserInfoDto userInfoDto = userService.getUserInfo(newUser.getUserId());
Expand Down

0 comments on commit e98a2ff

Please sign in to comment.