After the improving of performance4

This commit is contained in:
Your Name 2026-07-29 19:48:24 +02:00
parent c74036b8c6
commit 10592e0fe4
2 changed files with 39 additions and 13 deletions

View File

@ -30,7 +30,15 @@ function enrichRoundPayload(
const short = Number(pools.short ?? 0);
const long = Number(pools.long ?? 0);
const total = short + long;
if (total <= 0) return round;
if (total <= 0) {
// Empty pools must clear previous client state (do not omit zero amounts).
return {
...round,
shortPoolPercent: Number(round.shortPoolPercent ?? 0),
longPoolPercent: Number(round.longPoolPercent ?? 0),
...(includePoolAmounts ? { shortPool: 0, longPool: 0 } : {}),
};
}
const shortPoolPercent = Math.round((short / total) * 1000) / 10;
const longPoolPercent = Math.round((long / total) * 1000) / 10;
return {

View File

@ -26,24 +26,42 @@ function mergeRound(
): GameState['round'] {
if (!incoming) return prev ?? null;
const merged = { ...(prev ?? {}), ...incoming } as NonNullable<GameState['round']>;
const incomingRec = incoming as Record<string, unknown>;
const roundChanged =
prev?.id != null &&
incomingRec.id != null &&
String(prev.id) !== String(incomingRec.id);
const inShort = Number((incoming as { shortPool?: number }).shortPool ?? NaN);
const inLong = Number((incoming as { longPool?: number }).longPool ?? NaN);
const inPoolTotal =
(Number.isFinite(inShort) ? inShort : 0) + (Number.isFinite(inLong) ? inLong : 0);
if (inPoolTotal > 0) {
merged.shortPool = inShort;
merged.longPool = inLong;
const hasPoolAmounts =
Object.prototype.hasOwnProperty.call(incomingRec, 'shortPool') ||
Object.prototype.hasOwnProperty.call(incomingRec, 'longPool');
const inShort = Number(incomingRec.shortPool ?? NaN);
const inLong = Number(incomingRec.longPool ?? NaN);
if (hasPoolAmounts) {
// Explicit values win — including zeros for a fresh empty round.
merged.shortPool = Number.isFinite(inShort) ? inShort : 0;
merged.longPool = Number.isFinite(inLong) ? inLong : 0;
} else if (roundChanged) {
merged.shortPool = 0;
merged.longPool = 0;
} else if (prev) {
if (merged.shortPool == null && prev.shortPool != null) merged.shortPool = prev.shortPool;
if (merged.longPool == null && prev.longPool != null) merged.longPool = prev.longPool;
}
const inShortPct = Number((incoming as { shortPoolPercent?: number }).shortPoolPercent ?? NaN);
const inLongPct = Number((incoming as { longPoolPercent?: number }).longPoolPercent ?? NaN);
if (Number.isFinite(inShortPct) && Number.isFinite(inLongPct) && inShortPct + inLongPct > 0) {
merged.shortPoolPercent = inShortPct;
merged.longPoolPercent = inLongPct;
const hasPoolPercents =
Object.prototype.hasOwnProperty.call(incomingRec, 'shortPoolPercent') ||
Object.prototype.hasOwnProperty.call(incomingRec, 'longPoolPercent');
const inShortPct = Number(incomingRec.shortPoolPercent ?? NaN);
const inLongPct = Number(incomingRec.longPoolPercent ?? NaN);
if (hasPoolPercents) {
merged.shortPoolPercent = Number.isFinite(inShortPct) ? inShortPct : 0;
merged.longPoolPercent = Number.isFinite(inLongPct) ? inLongPct : 0;
} else if (roundChanged) {
merged.shortPoolPercent = 0;
merged.longPoolPercent = 0;
}
merged.status = effectiveRoundStatus(merged);