-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 방어 전투 로그 조회할 수 있는 기능 추가, 성능 개선 #90
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 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.ezcode.codetest.application.game.dto.response.encounter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import org.ezcode.codetest.domain.game.model.encounter.BattleHistory; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| @Schema(description = "캐릭터 방어 전투 결과 응답") | ||
| public record DefenceBattleHistoryResponse( | ||
|
|
||
| @Schema(description = "공격자 캐릭터 닉네임") | ||
| String attackerNickName, | ||
|
|
||
| @Schema(description = "플레이어 캐릭터 닉네임") | ||
| String PlayerNickName, | ||
|
|
||
| @Schema(description = "전투 로그") | ||
| String battleLog, | ||
|
|
||
| @Schema(description = "플레이어 승패 여부(이겼을시 true, 패배시 false)") | ||
| boolean isDefenderWin, | ||
|
|
||
| @Schema(description = "PVP 가 일어난 시점") | ||
| LocalDateTime battleCreatedAt | ||
|
|
||
| ) { | ||
| public static DefenceBattleHistoryResponse from(BattleHistory history) { | ||
| return DefenceBattleHistoryResponse.builder() | ||
| .attackerNickName(history.getAttacker().getName()) | ||
| .PlayerNickName(history.getDefender().getName()) | ||
| .battleLog(history.getBattleLog()) | ||
| .isDefenderWin(!history.getIsAttackerWin()) | ||
| .battleCreatedAt(history.getCreatedAt()) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||
|
|
||||||
| import org.ezcode.codetest.domain.game.model.encounter.EncounterChoice; | ||||||
| import org.ezcode.codetest.domain.game.repository.EncounterChoiceRepository; | ||||||
| import org.springframework.cache.annotation.Cacheable; | ||||||
| import org.springframework.stereotype.Repository; | ||||||
|
|
||||||
| import lombok.RequiredArgsConstructor; | ||||||
|
|
@@ -34,6 +35,7 @@ public Optional<EncounterChoice> findByName(String name) { | |||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @Cacheable(value = "choices", key = "#encounterId + '-' + #playerDecision") | ||||||
|
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. 🛠️ Refactor suggestion 캐시 키 생성 방식을 개선하세요. 현재 문자열 연결 방식("#encounterId + '-' + #playerDecision")은 잠재적인 키 충돌을 일으킬 수 있습니다. SpEL의 컬렉션 구문을 사용하여 더 안전한 키를 생성하는 것을 권장합니다. - @Cacheable(value = "choices", key = "#encounterId + '-' + #playerDecision")
+ @Cacheable(value = "choices", key = "{#encounterId, #playerDecision}")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
Author
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. @Cacheable(value = "choices", key = "#encounterId + '-' + #playerDecision")
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.
Collaborator
Author
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. @coderabbitai 둘차이가 머냐고 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. @chat26666 두 방식의 주요 차이점을 설명드리겠습니다: 1. 문자열 연결 방식 (현재)@Cacheable(value = "choices", key = "#encounterId + '-' + #playerDecision")
2. SpEL 컬렉션 구문 (권장)@Cacheable(value = "choices", key = "{#encounterId, #playerDecision}")
주요 차이점1. 키 충돌 위험성
2. 타입 안전성
3. 성능
컬렉션 구문 🧠 Learnings used |
||||||
| public List<EncounterChoice> findChoiceByPlayerDecision(Long encounterId, boolean playerDecision) { | ||||||
|
|
||||||
| return encounterRepository.findByEncounterIdAndPlayerDecision(encounterId, playerDecision); | ||||||
|
|
||||||
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.
🛠️ Refactor suggestion
시간대 처리를 명시적으로 관리하세요.
LocalDateTime.now()는 시스템 시간대에 의존하므로 다국가 서비스에서 예상치 못한 결과를 초래할 수 있습니다. UTC 기준으로 시간을 처리하거나 애플리케이션의 표준 시간대를 명시적으로 사용하는 것을 권장합니다.추가로
java.time.ZoneOffsetimport가 필요합니다.🤖 Prompt for AI Agents