Skip to content

Commit 512d2b7

Browse files
authored
Merge pull request #138 from howWeather/perf/model-request
fix: 엔티티 상태 저장 및 새 데이터 가져오도록 명시
2 parents bb99288 + dae2b41 commit 512d2b7

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/com/howWeather/howWeather_backend/domain/ai_model/repository/ClothingRecommendationRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.howWeather.howWeather_backend.domain.ai_model.repository;
22

33
import com.howWeather.howWeather_backend.domain.ai_model.entity.ClothingRecommendation;
4+
import jakarta.persistence.QueryHint;
45
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.jpa.repository.QueryHints;
57
import org.springframework.stereotype.Repository;
68
import org.springframework.transaction.annotation.Transactional;
79

@@ -10,6 +12,7 @@
1012

1113
@Repository
1214
public interface ClothingRecommendationRepository extends JpaRepository<ClothingRecommendation, Long> {
15+
@QueryHints({ @QueryHint(name = "javax.persistence.cache.retrieveMode", value = "BYPASS") })
1316
List<ClothingRecommendation> findByMemberIdAndDate(Long memberId, LocalDate date);
1417

1518
void deleteByDateBefore(LocalDate date);

src/main/java/com/howWeather/howWeather_backend/domain/ai_model/service/RecommendationService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public List<RecommendPredictDto> getRecommendList(Member member) {
4949
List<RecommendPredictDto> result = new ArrayList<>();
5050
for (ClothingRecommendation recommendation : modelPredictList) {
5151
RecommendPredictDto dto = makeResultForPredict(closet, recommendation, member);
52-
if (dto.getUppersTypeList() != null && !dto.getUppersTypeList().isEmpty()) {
52+
53+
boolean isUppersExist = dto.getUppersTypeList() != null && !dto.getUppersTypeList().isEmpty();
54+
boolean isFeelingExist = dto.getFeelingList() != null && !dto.getFeelingList().isEmpty();
55+
56+
if (isUppersExist && isFeelingExist) {
5357
result.add(dto);
5458
}
5559
}

src/main/java/com/howWeather/howWeather_backend/domain/member/service/MyAccountService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.howWeather.howWeather_backend.global.cipher.AESCipher;
2121
import com.howWeather.howWeather_backend.global.exception.CustomException;
2222
import com.howWeather.howWeather_backend.global.exception.ErrorCode;
23+
import jakarta.persistence.EntityManager;
2324
import org.springframework.beans.factory.annotation.Value;
2425
import org.springframework.http.HttpEntity;
2526
import org.springframework.http.HttpHeaders;
@@ -41,10 +42,10 @@
4142
@Service
4243
@RequiredArgsConstructor
4344
public class MyAccountService {
45+
private final EntityManager entityManager;
4446
private final WeatherForecastRepository weatherForecastRepository;
4547
private final MemberRepository memberRepository;
4648
private final ClothingRecommendationRepository recommendationRepository;
47-
private final RecommendationService recommendationService;
4849
private final DailyCombinationScheduler dailyCombinationScheduler;
4950
private final AiInternalService aiInternalService;
5051
private final RestTemplate restTemplate;
@@ -320,6 +321,8 @@ public void saveRecommendationsInternal(Map<String, String> encryptedData, Strin
320321
}
321322

322323
log.info("[추천 데이터 저장 완료] memberId={}", member.getId());
324+
recommendationRepository.flush();
325+
entityManager.clear();
323326
} else {
324327
List<ClothingRecommendation> existingData =
325328
recommendationRepository.findByMemberIdAndDate(member.getId(), LocalDate.now());
@@ -339,8 +342,9 @@ public void saveRecommendationsInternal(Map<String, String> encryptedData, Strin
339342
.build();
340343

341344
recommendationRepository.save(updatedEntity);
342-
recommendationRepository.flush();
343345
}
346+
recommendationRepository.flush();
347+
entityManager.clear();
344348

345349
log.info("[기존 데이터 지역명 업데이트 완료] memberId={}", member.getId());
346350
}
@@ -352,6 +356,7 @@ public void saveRecommendationsInternal(Map<String, String> encryptedData, Strin
352356
throw new CustomException(ErrorCode.UNKNOWN_ERROR, "지역명 업데이트 중 오류가 발생했습니다.");
353357
}
354358
}
359+
355360
private ClothingRecommendation convertToEntityWithBuilder(ModelRecommendationResult dto, Long memberId, String regionName) {
356361
return ClothingRecommendation.builder()
357362
.memberId(memberId)

0 commit comments

Comments
 (0)