서버 알림목록 로딩이슈
This commit is contained in:
@@ -10,14 +10,6 @@ import { getCandleStart, TF_SECONDS } from '../utils/upbitApi';
|
||||
import { DISPLAY_COUNT, WARMUP_COUNT, OBV_DEEP_HISTORY } from './useUpbitData';
|
||||
import type { WsStatus } from './useUpbitData';
|
||||
import { API_BASE } from '../utils/backendApi';
|
||||
import { fetchUpbitCandlesCached } from '../utils/requestCache';
|
||||
|
||||
/** 초기 렌더 최소 봉 수 — 미만이면 업비트 REST 폴백 */
|
||||
const MIN_INITIAL_BARS = Math.min(50, Math.floor(DISPLAY_COUNT / 4));
|
||||
|
||||
function barsHaveVolume(bars: OHLCVBar[]): boolean {
|
||||
return bars.some(b => (Number(b.volume) || 0) > 0);
|
||||
}
|
||||
|
||||
/** 백엔드 BarBuilder 는 틱마다 1m 만 STOMP 발행 — 차트 분봉은 클라이언트에서 집계 */
|
||||
const STOMP_TICK_CANDLE_TYPE = '1m';
|
||||
@@ -110,50 +102,22 @@ async function fetchInitialBarsWithRetry(
|
||||
throw lastErr ?? new Error('history fetch failed');
|
||||
}
|
||||
|
||||
/** 백엔드 history → 부족·거래량 0·실패 시 업비트 REST 폴백 */
|
||||
/**
|
||||
* 백엔드 /api/candles/history 에서만 초기 캔들을 로드한다.
|
||||
* Upbit REST 직접 호출을 하지 않음 — 백엔드가 데이터를 아직 쌓지 못한 경우
|
||||
* 빈 배열을 반환하고, 호출부에서 STOMP bootstrap 경로로 처리한다.
|
||||
*/
|
||||
async function loadInitialBars(
|
||||
market: string,
|
||||
timeframe: Timeframe,
|
||||
count: number,
|
||||
marketChanged: boolean,
|
||||
preferUpbit = false,
|
||||
): Promise<OHLCVBar[]> {
|
||||
const candleType = timeframeToCandleType(timeframe);
|
||||
const upbitCount = Math.min(count, OBV_DEEP_HISTORY);
|
||||
|
||||
if (preferUpbit) {
|
||||
try {
|
||||
const upbit = await fetchUpbitCandlesCached(market, timeframe, upbitCount, marketChanged);
|
||||
if (upbit.length >= MIN_INITIAL_BARS && barsHaveVolume(upbit)) return upbit;
|
||||
} catch {
|
||||
/* Upbit 실패 시 backend 시도 */
|
||||
}
|
||||
}
|
||||
|
||||
let bars: OHLCVBar[] = [];
|
||||
try {
|
||||
bars = await fetchInitialBarsWithRetry(market, candleType, count);
|
||||
return await fetchInitialBarsWithRetry(market, candleType, count);
|
||||
} catch {
|
||||
bars = [];
|
||||
return [];
|
||||
}
|
||||
|
||||
const needsUpbitFallback = bars.length < MIN_INITIAL_BARS || !barsHaveVolume(bars);
|
||||
if (needsUpbitFallback) {
|
||||
try {
|
||||
const fallback = await fetchUpbitCandlesCached(
|
||||
market,
|
||||
timeframe,
|
||||
upbitCount,
|
||||
marketChanged,
|
||||
);
|
||||
if (fallback.length > bars.length || (barsHaveVolume(fallback) && !barsHaveVolume(bars))) {
|
||||
bars = fallback;
|
||||
}
|
||||
} catch {
|
||||
/* 폴백 실패 시 backend 결과 유지 */
|
||||
}
|
||||
}
|
||||
return bars;
|
||||
}
|
||||
|
||||
export function useStompChartData(
|
||||
@@ -180,8 +144,6 @@ export function useStompChartData(
|
||||
const historyReadyRef = useRef(false);
|
||||
/** 백엔드 history 비어 있을 때 STOMP 누적 → React bars 동기화 */
|
||||
const bootstrapFromStompRef = useRef(false);
|
||||
const prevMarketRef = useRef('');
|
||||
|
||||
useEffect(() => {
|
||||
if (opts.enabled === false) return;
|
||||
let cancelled = false;
|
||||
@@ -196,13 +158,10 @@ export function useStompChartData(
|
||||
last1mTimeRef.current = 0;
|
||||
lastTimeRef.current = 0;
|
||||
|
||||
const marketChanged = prevMarketRef.current !== '' && prevMarketRef.current !== market;
|
||||
prevMarketRef.current = market;
|
||||
|
||||
const count = opts.deepObvHistory
|
||||
? OBV_DEEP_HISTORY
|
||||
: DISPLAY_COUNT + WARMUP_COUNT;
|
||||
loadInitialBars(market, timeframe, count, marketChanged, opts.deepObvHistory === true)
|
||||
loadInitialBars(market, timeframe, count)
|
||||
.then(newBars => {
|
||||
if (cancelled) return;
|
||||
barsRef.current = newBars;
|
||||
|
||||
Reference in New Issue
Block a user