After the improving of performance3
This commit is contained in:
parent
680901591a
commit
c74036b8c6
@ -101,11 +101,12 @@ export function CandlePredictPage() {
|
||||
const autoMut = useAutoPredictionSettings();
|
||||
|
||||
const balancePollMs = useMemo(() => {
|
||||
if (!round) return 15_000;
|
||||
if (round.status === 'locked') return 5_000;
|
||||
if (round.status === 'betting') return 12_000;
|
||||
if (round.status === 'settled' || round.outcome) return 8_000;
|
||||
return 15_000;
|
||||
// Balances refresh on bet/settle events; background poll is only a safety net.
|
||||
if (!round) return 60_000;
|
||||
if (round.status === 'locked') return 20_000;
|
||||
if (round.status === 'betting') return 45_000;
|
||||
if (round.status === 'settled' || round.outcome) return 30_000;
|
||||
return 60_000;
|
||||
}, [round?.status, round?.outcome]);
|
||||
|
||||
const balancesQ = useLiveBalances({ refetchIntervalMs: balancePollMs });
|
||||
|
||||
@ -78,7 +78,7 @@ function withLightJitter(baseMs: number, ratio = 0.12): number {
|
||||
return Math.max(1000, baseMs + offset);
|
||||
}
|
||||
|
||||
export function useCandlePredictState(intervalMinutes?: number, pollMs = 3000) {
|
||||
export function useCandlePredictState(intervalMinutes?: number, _pollMs = 3000) {
|
||||
const wsEnabled = isWsEnabled();
|
||||
const socket = useGameSocket(intervalMinutes);
|
||||
const stateCacheKey = stateCacheKeyFor(intervalMinutes);
|
||||
@ -95,11 +95,30 @@ export function useCandlePredictState(intervalMinutes?: number, pollMs = 3000) {
|
||||
if (res.status === 304 && cached) {
|
||||
return cached.data;
|
||||
}
|
||||
const next = res.data;
|
||||
// Avoid re-render when payload is timer-only churn (same round/status/pools).
|
||||
if (
|
||||
cached?.data?.round?.id &&
|
||||
next?.round?.id === cached.data.round.id &&
|
||||
next?.round?.status === cached.data.round.status &&
|
||||
next?.round?.outcome === cached.data.round.outcome &&
|
||||
next?.round?.shortPool === cached.data.round.shortPool &&
|
||||
next?.round?.longPool === cached.data.round.longPool &&
|
||||
next?.userBet?.id === cached.data.userBet?.id &&
|
||||
next?.userMultiBet?.id === cached.data.userMultiBet?.id &&
|
||||
next?.autoSettings?.enabled === cached.data.autoSettings?.enabled
|
||||
) {
|
||||
stateEtagCache.set(stateCacheKey, {
|
||||
etag: String(res.headers.etag ?? cached.etag),
|
||||
data: cached.data,
|
||||
});
|
||||
return cached.data;
|
||||
}
|
||||
stateEtagCache.set(stateCacheKey, {
|
||||
etag: String(res.headers.etag ?? ''),
|
||||
data: res.data,
|
||||
data: next,
|
||||
});
|
||||
return res.data;
|
||||
return next;
|
||||
},
|
||||
retry: (failureCount, error) => {
|
||||
const status = (error as { response?: { status?: number } })?.response?.status;
|
||||
@ -107,19 +126,18 @@ export function useCandlePredictState(intervalMinutes?: number, pollMs = 3000) {
|
||||
return failureCount < 1;
|
||||
},
|
||||
refetchInterval: (query) => {
|
||||
// WS is primary for round transitions; HTTP is a rare safety net only.
|
||||
if (wsEnabled && socket.status === 'connected') {
|
||||
const data = query.state.data;
|
||||
if (data?.userMultiBet) return withLightJitter(8000);
|
||||
if (data?.autoSettings?.enabled) return withLightJitter(7000);
|
||||
if (data?.round?.status === 'betting') return withLightJitter(8000);
|
||||
return withLightJitter(20000);
|
||||
return withLightJitter(60_000, 0.05);
|
||||
}
|
||||
if (wsEnabled && (socket.status === 'reconnecting' || socket.status === 'stale')) {
|
||||
return withLightJitter(2500, 0.08);
|
||||
return withLightJitter(8_000, 0.08);
|
||||
}
|
||||
const status = query.state.data?.round?.status;
|
||||
return withLightJitter(status === 'betting' ? 2000 : pollMs, 0.08);
|
||||
return withLightJitter(status === 'betting' ? 5_000 : 15_000, 0.08);
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
structuralSharing: true,
|
||||
});
|
||||
}
|
||||
|
||||
@ -179,7 +197,7 @@ export function useMyCandlePredictions(
|
||||
) {
|
||||
|
||||
const pollMs =
|
||||
opts?.roundStatus === 'betting' || opts?.autoEnabled ? 8000 : 20_000;
|
||||
opts?.roundStatus === 'betting' || opts?.autoEnabled ? 30_000 : 60_000;
|
||||
|
||||
|
||||
|
||||
@ -214,6 +232,7 @@ export function useMyCandlePredictions(
|
||||
},
|
||||
|
||||
refetchInterval: pollMs,
|
||||
refetchOnWindowFocus: false,
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -51,6 +51,28 @@ function mergeRound(
|
||||
return merged;
|
||||
}
|
||||
|
||||
/** True when UI-relevant round fields changed (ignore ticking countdown fields). */
|
||||
function roundUiChanged(
|
||||
prev: GameState['round'] | null | undefined,
|
||||
next: GameState['round'] | null | undefined
|
||||
): boolean {
|
||||
if (prev === next) return false;
|
||||
if (!prev || !next) return true;
|
||||
return (
|
||||
prev.id !== next.id ||
|
||||
prev.status !== next.status ||
|
||||
prev.outcome !== next.outcome ||
|
||||
prev.settledAt !== next.settledAt ||
|
||||
prev.candleOpenMs !== next.candleOpenMs ||
|
||||
prev.shortPool !== next.shortPool ||
|
||||
prev.longPool !== next.longPool ||
|
||||
prev.shortPoolPercent !== next.shortPoolPercent ||
|
||||
prev.longPoolPercent !== next.longPoolPercent ||
|
||||
prev.openPrice !== next.openPrice ||
|
||||
prev.closePrice !== next.closePrice
|
||||
);
|
||||
}
|
||||
|
||||
function userBetForRound(
|
||||
userBet: GameState['userBet'],
|
||||
round: GameState['round']
|
||||
@ -136,6 +158,10 @@ export function useGameSocket(
|
||||
qc.setQueryData<GameState | undefined>(key, (prev) => {
|
||||
if (!prev) return prev;
|
||||
const round = mergeRound(prev.round, msg.round);
|
||||
if (!roundUiChanged(prev.round, round)) {
|
||||
// Timer-only engine ticks: keep same object so the page does not re-render.
|
||||
return prev;
|
||||
}
|
||||
return {
|
||||
...prev,
|
||||
round,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user