Skip to content

Commit 0502cb5

Browse files
committed
refactor(cache): 캐시 키 및 페이로드 관련 코드 개선
- 일간 랭킹 키 생성 시 날짜 형식 변경 - EventType의 weight 필드를 final로 변경하여 불변성 강화 - 로그 메시지에서 잘못된 이벤트 타입 수정 - API 문서에서 날짜 형식 설명 업데이트
1 parent a93dad6 commit 0502cb5

6 files changed

Lines changed: 11 additions & 11 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/interfaces/api/product/ProductV1ApiSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ApiResponse<PageResponse<ProductV1Dtos.ProductListResponse>> getProducts(
4444
})
4545
ApiResponse<PageResponse<ProductV1Dtos.ProductListResponse>> getRankingProducts(
4646
@PageableDefault(size = 20) Pageable pageable,
47-
@Parameter(description = "조회 날짜 (yyyyMMdd 형식, 선택)", example = "20251223")
47+
@Parameter(description = "조회 날짜 (yyyy-MM-dd 형식, 선택)", example = "2025-12-23")
4848
@RequestParam(required = false) LocalDate date
4949
);
5050

apps/commerce-streamer/src/main/java/com/loopers/CommerceStreamerApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
77
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
8+
import org.springframework.scheduling.annotation.EnableScheduling;
89

910
import jakarta.annotation.PostConstruct;
1011

1112
@ConfigurationPropertiesScan
1213
@SpringBootApplication
14+
@EnableScheduling
1315
public class CommerceStreamerApplication {
1416
@PostConstruct
1517
public void started() {

apps/commerce-streamer/src/main/java/com/loopers/interfaces/consumer/MetricsKafkaConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void onOrderEvents(
9191
var result = eventProcessingFacade.processOrderEvent(record.value());
9292
return (result.processed()) ? result.rankingScore() : null;
9393
} catch (Exception e) {
94-
log.error("Failed to process catalog event", e);
94+
log.error("Failed to process order event", e);
9595
return null;
9696
}
9797
}, executorService))

apps/commerce-streamer/src/test/java/com/loopers/interfaces/consumer/MetricsKafkaConsumerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.mockito.ArgumentMatchers.*;
44
import static org.mockito.Mockito.*;
5-
65
import java.util.List;
76

87
import org.apache.kafka.clients.consumer.ConsumerRecord;
@@ -156,7 +155,10 @@ void shouldContinueProcessingWhenIndividualMessageFails() {
156155
consumer.onCatalogEvents(List.of(validRecord, invalidRecord), acknowledgment);
157156

158157
// Then - 유효한 메시지는 처리되고, 전체 배치는 ack 되어야 함
159-
verify(eventProcessingFacade, times(2)).processCatalogEvent(any());
158+
verify(eventProcessingFacade, times(1)).updateRankingScores(
159+
argThat(list -> list.size() == 1),
160+
isNull()
161+
);
160162
verify(acknowledgment, times(1)).acknowledge();
161163
}
162164

modules/redis/src/main/java/com/loopers/cache/CacheKeyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private String generateSortString(Sort sort) {
135135
}
136136

137137
/**
138-
* 일간 랭킹 키 생성: ranking:all:20251223
138+
* 일간 랭킹 키 생성: ranking:all:2025-12-23
139139
*/
140140
public String generateDailyRankingKey(LocalDate date) {
141141
return new StringJoiner(DELIMITER)

modules/redis/src/main/java/com/loopers/cache/dto/CachePayloads.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ public enum EventType {
3030
LIKE_ACTION(0.2), // 좋아요: Weight = 0.2, Score = 1
3131
PAYMENT_SUCCESS(0.6); // 주문: Weight = 0.6, Score = price * amount (정규화 시에는 log 적용도 가능)
3232

33-
private double weight;
33+
private final double weight;
3434

3535
EventType(double weight) {
3636
this.weight = weight;
3737
}
38-
39-
public void setWeight(double weight) {
40-
this.weight = weight;
41-
}
4238
}
4339

4440
/**
@@ -58,7 +54,7 @@ public static RankingScore forProductView(Long productId, long occurredAt) {
5854
}
5955

6056
/**
61-
* 좋아요 이벤트 생성 생성
57+
* 좋아요 이벤트 생성
6258
*/
6359
public static RankingScore forLikeAction(Long productId, long occurredAt) {
6460
return new RankingScore(productId, EventType.LIKE_ACTION, 1.0, occurredAt);

0 commit comments

Comments
 (0)