서버 알림목록 오류 수정
This commit is contained in:
@@ -184,10 +184,25 @@ export const TradeNotificationListPage: React.FC<Props> = ({
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
let retryTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const load = () => {
|
||||
void prefetchNotificationStrategies().then(list => {
|
||||
if (!cancelled) setStrategies(list);
|
||||
if (cancelled) return;
|
||||
if (list.length > 0) {
|
||||
setStrategies(list);
|
||||
} else {
|
||||
// 백엔드 미준비(Docker 기동 초기)로 빈 목록이 반환된 경우 5초 후 재시도
|
||||
retryTimer = setTimeout(load, 5000);
|
||||
}
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
};
|
||||
|
||||
load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (retryTimer) clearTimeout(retryTimer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const tradePrice = useMemo(
|
||||
|
||||
@@ -18,8 +18,11 @@ import {
|
||||
|
||||
/** 전략을 찾았지만 백엔드가 아직 조건을 평가하지 않은 경우 — warm-up 대기 (10분) */
|
||||
const MAX_EMPTY_RETRIES_WARM = 200;
|
||||
/** 전략 자체를 찾지 못한 경우 — 빠르게 "데이터 없음" 표시 */
|
||||
const MAX_EMPTY_RETRIES_NO_STRATEGY = 3;
|
||||
/**
|
||||
* 전략 자체를 아직 찾지 못한 경우 — 서버 시작 초기(전략 목록 미로드)를 고려해 1분 대기
|
||||
* 3 → 20: Docker 기동 직후 백엔드가 전략 목록 API를 응답하기까지 시간이 걸릴 수 있음
|
||||
*/
|
||||
const MAX_EMPTY_RETRIES_NO_STRATEGY = 20;
|
||||
|
||||
function staticFallback(
|
||||
market: string,
|
||||
|
||||
@@ -27,16 +27,20 @@ export function normalizeStrategyId(id: unknown): number | null {
|
||||
|
||||
async function getStrategiesList(force = false): Promise<StrategyDto[]> {
|
||||
const now = Date.now();
|
||||
if (!force && strategiesCache && now - strategiesCacheAt < CACHE_MS) {
|
||||
// 빈 배열은 캐시하지 않는다 — 백엔드 미준비로 빈 결과가 반환된 경우 재시도 허용
|
||||
if (!force && strategiesCache && strategiesCache.length > 0 && now - strategiesCacheAt < CACHE_MS) {
|
||||
return strategiesCache;
|
||||
}
|
||||
const list = await loadStrategies();
|
||||
strategiesCache = list ?? [];
|
||||
const result = list ?? [];
|
||||
if (result.length > 0) {
|
||||
strategiesCache = result;
|
||||
strategiesCacheAt = now;
|
||||
reconcileStrategyMissingWithValidIds(
|
||||
strategiesCache.map(s => s.id).filter((id): id is number => id != null && id > 0),
|
||||
result.map(s => s.id).filter((id): id is number => id != null && id > 0),
|
||||
);
|
||||
return strategiesCache;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function findStrategyByName(list: StrategyDto[], name: string): StrategyDto | undefined {
|
||||
@@ -74,7 +78,8 @@ export async function resolveNotificationStrategy(
|
||||
market?: string | null,
|
||||
): Promise<ResolvedNotificationStrategy> {
|
||||
const normalizedId = normalizeStrategyId(strategyId);
|
||||
const list = prefetched ?? await getStrategiesList();
|
||||
// prefetched가 빈 배열이면 직접 API로 재시도 (백엔드 미준비 시 prefetch가 빈 채로 캐시될 수 있음)
|
||||
const list = (prefetched != null && prefetched.length > 0) ? prefetched : await getStrategiesList();
|
||||
|
||||
if (normalizedId != null) {
|
||||
const fromList = list.find(s => s.id === normalizedId);
|
||||
|
||||
Reference in New Issue
Block a user