Improve auction realtime bid responsiveness
This commit is contained in:
1 parent
c6f5a7077f
commit
b367328df0
16 files changed
+1364
-203
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
lazy,
|
||||
memo,
|
||||
Suspense,
|
||||
useEffect,
|
||||
useMemo,
|
||||
@@ -26,7 +27,10 @@ import {
|
||||
type AuctionPlayerView,
|
||||
type AuctionStateView,
|
||||
} from '../api/mappers';
|
||||
import { useAuctionSocket } from '../api/useAuctionSocket';
|
||||
import {
|
||||
useAuctionSocket,
|
||||
type BidLatencyDiagnostics,
|
||||
} from '../api/useAuctionSocket';
|
||||
import {
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
setDevCaptainTeamIndex,
|
||||
@@ -176,6 +180,53 @@ function getMaxBidForTeam(team: AuctionStateView['teams'][number]) {
|
||||
return Math.max(0, team.points - getReservedPointsAfterCurrentBid(team));
|
||||
}
|
||||
|
||||
function formatLatencyMs(value: number | undefined) {
|
||||
return typeof value === 'number' && Number.isFinite(value)
|
||||
? `${Math.round(value)}ms`
|
||||
: '-';
|
||||
}
|
||||
|
||||
function formatBidLatencyDiagnostics(
|
||||
diagnostics: BidLatencyDiagnostics | null,
|
||||
) {
|
||||
if (!diagnostics) return null;
|
||||
|
||||
const serverDeadlineTimestampMS =
|
||||
diagnostics.bidDiagnostics?.currentBidRoundDeadlineTimestampMS;
|
||||
const serverTimestampMS = diagnostics.bidDiagnostics?.currentServerTimestampMS;
|
||||
const serverRemainingMS =
|
||||
typeof diagnostics.serverObservedRemainingBidRoundTimeMS === 'number'
|
||||
? diagnostics.serverObservedRemainingBidRoundTimeMS
|
||||
: typeof serverDeadlineTimestampMS === 'number' &&
|
||||
typeof serverTimestampMS === 'number'
|
||||
? serverDeadlineTimestampMS - serverTimestampMS
|
||||
: undefined;
|
||||
const timing = diagnostics.bidServerTiming;
|
||||
const parts = [
|
||||
`RTT ${formatLatencyMs(diagnostics.serverRoundTripDurationMS)}`,
|
||||
`gateway ${formatLatencyMs(timing?.gatewayTotalDurationMS)}`,
|
||||
`service ${formatLatencyMs(timing?.serviceTotalDurationMS)}`,
|
||||
`redis ${formatLatencyMs(timing?.redisBidCommandDurationMS)}`,
|
||||
`context ${formatLatencyMs(timing?.redisBidContextReadDurationMS)}`,
|
||||
];
|
||||
|
||||
if (timing?.fallbackFullStatePath) {
|
||||
parts.push('fallback full-state');
|
||||
}
|
||||
if (typeof diagnostics.clientObservedRemainingBidRoundTimeMS === 'number') {
|
||||
parts.push(
|
||||
`client-left ${formatLatencyMs(
|
||||
diagnostics.clientObservedRemainingBidRoundTimeMS,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
if (typeof serverRemainingMS === 'number') {
|
||||
parts.push(`server-left ${formatLatencyMs(serverRemainingMS)}`);
|
||||
}
|
||||
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
function getSoloTierHistory(entries: ApiTierHistoryEntry[]) {
|
||||
return entries.filter((entry) => entry.queueType === 'RANKED_SOLO_5x5');
|
||||
}
|
||||
@@ -196,7 +247,7 @@ function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
|
||||
return (
|
||||
<div className="w-full h-1.5 bg-base-content/5">
|
||||
<div
|
||||
className={`h-full transition-all duration-1000 linear ${urgent ? 'bg-red-500' : 'bg-primary'}`}
|
||||
className={`h-full transition-all duration-300 linear ${urgent ? 'bg-red-500' : 'bg-primary'}`}
|
||||
style={{ width: `${pct}%` }}
|
||||
/>
|
||||
</div>
|
||||
@@ -426,6 +477,8 @@ function TeamPanel({
|
||||
);
|
||||
}
|
||||
|
||||
const MemoTeamPanel = memo(TeamPanel);
|
||||
|
||||
function PlayerSpotlight({
|
||||
state,
|
||||
historyBackTo,
|
||||
@@ -433,24 +486,52 @@ function PlayerSpotlight({
|
||||
state: AuctionStateView;
|
||||
historyBackTo: string;
|
||||
}) {
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const player = state.currentPlayer;
|
||||
const snapshotSoloTierHistory = player
|
||||
? getSoloTierHistory(player.tierHistory)
|
||||
: [];
|
||||
const historyProfileQuery = useUserHistoryProfile(
|
||||
player?.userId,
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
Boolean(player && snapshotSoloTierHistory.length === 0),
|
||||
);
|
||||
if (!player) return null;
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100">
|
||||
<MemoPlayerProfileDetails player={player} historyBackTo={historyBackTo} />
|
||||
<PlayerBidStatus state={state} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const MemoPlayerSpotlight = memo(
|
||||
PlayerSpotlight,
|
||||
(previous, next) =>
|
||||
previous.historyBackTo === next.historyBackTo &&
|
||||
areSameAuctionPlayerProfile(
|
||||
previous.state.currentPlayer,
|
||||
next.state.currentPlayer,
|
||||
) &&
|
||||
previous.state.phase === next.state.phase &&
|
||||
previous.state.currentBid === next.state.currentBid &&
|
||||
previous.state.currentBidder?.teamIndex === next.state.currentBidder?.teamIndex &&
|
||||
previous.state.auctionRound === next.state.auctionRound,
|
||||
);
|
||||
|
||||
function PlayerProfileDetails({
|
||||
player,
|
||||
historyBackTo,
|
||||
}: {
|
||||
player: NonNullable<AuctionStateView['currentPlayer']>;
|
||||
historyBackTo: string;
|
||||
}) {
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const snapshotSoloTierHistory = getSoloTierHistory(player.tierHistory);
|
||||
const historyProfileQuery = useUserHistoryProfile(
|
||||
player.userId,
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
snapshotSoloTierHistory.length === 0,
|
||||
);
|
||||
const tierHistory =
|
||||
snapshotSoloTierHistory.length > 0
|
||||
? snapshotSoloTierHistory
|
||||
: getSoloTierHistory(historyProfileQuery.data?.tierHistory ?? []);
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100">
|
||||
<>
|
||||
<div className="p-5 border-b border-base-content/8">
|
||||
<div className="flex items-start gap-4">
|
||||
<Link
|
||||
@@ -557,7 +638,41 @@ function PlayerSpotlight({
|
||||
|
||||
<RecentSoloStats player={player} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const MemoPlayerProfileDetails = memo(
|
||||
PlayerProfileDetails,
|
||||
(previous, next) =>
|
||||
areSameAuctionPlayerProfile(previous.player, next.player) &&
|
||||
previous.historyBackTo === next.historyBackTo,
|
||||
);
|
||||
|
||||
function areSameAuctionPlayerProfile(
|
||||
previous: AuctionPlayerView | null,
|
||||
next: AuctionPlayerView | null,
|
||||
) {
|
||||
if (previous === next) return true;
|
||||
if (!previous || !next) return false;
|
||||
return (
|
||||
previous.userId === next.userId &&
|
||||
previous.summonerName === next.summonerName &&
|
||||
previous.tag === next.tag &&
|
||||
previous.mainPosition === next.mainPosition &&
|
||||
previous.subPosition === next.subPosition &&
|
||||
previous.profileIconId === next.profileIconId &&
|
||||
previous.passCount === next.passCount &&
|
||||
JSON.stringify(previous.tier) === JSON.stringify(next.tier) &&
|
||||
JSON.stringify(previous.tierHistory) === JSON.stringify(next.tierHistory) &&
|
||||
JSON.stringify(previous.masteries) === JSON.stringify(next.masteries) &&
|
||||
JSON.stringify(previous.recentStats) === JSON.stringify(next.recentStats)
|
||||
);
|
||||
}
|
||||
|
||||
function PlayerBidStatus({ state }: { state: AuctionStateView }) {
|
||||
return (
|
||||
<>
|
||||
{(state.phase === 'bidding' || state.phase === 'sold') && (
|
||||
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -589,7 +704,7 @@ function PlayerSpotlight({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -616,6 +731,10 @@ function BidControls({
|
||||
: 0;
|
||||
const maxBid = activeTeam ? getMaxBidForTeam(activeTeam) : 0;
|
||||
const canAffordNextBid = !isActiveTeamFull && maxBid >= minBid;
|
||||
const isBidExpired = state.remainingMs <= 0;
|
||||
const effectiveBidAmount = activeTeam
|
||||
? Math.min(maxBid, Math.max(minBid, bidAmount))
|
||||
: Math.max(minBid, bidAmount);
|
||||
|
||||
useEffect(() => {
|
||||
const nextBid = Math.max(minBid, Math.ceil(minBid / 10) * 10);
|
||||
@@ -692,12 +811,13 @@ function BidControls({
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => onBid(activeTeam.teamIndex, bidAmount)}
|
||||
onClick={() => onBid(activeTeam.teamIndex, effectiveBidAmount)}
|
||||
disabled={
|
||||
isBidPending ||
|
||||
!canAffordNextBid ||
|
||||
bidAmount > maxBid ||
|
||||
bidAmount <= state.currentBid
|
||||
isBidExpired ||
|
||||
effectiveBidAmount > maxBid ||
|
||||
effectiveBidAmount <= state.currentBid
|
||||
}
|
||||
className={`w-full py-2 text-xs font-bold uppercase tracking-wide border transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${
|
||||
`${teamIndexColorClasses(activeTeam.teamIndex).border} ${teamIndexColorClasses(activeTeam.teamIndex).bg} ${teamIndexColorClasses(activeTeam.teamIndex).text} hover:bg-base-content/5`
|
||||
@@ -707,9 +827,11 @@ function BidControls({
|
||||
? `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
||||
: isBidPending
|
||||
? '입찰 반영 중...'
|
||||
: isBidExpired
|
||||
? '입찰 마감 확인 중'
|
||||
: !canAffordNextBid
|
||||
? `입찰 불가 (다음 ${formatPoints(minBid)}P · 최대 ${formatPoints(maxBid)}P)`
|
||||
: `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 입찰 (${formatPoints(bidAmount)}P)`}
|
||||
: `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 입찰 (${formatPoints(effectiveBidAmount)}P)`}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
@@ -752,6 +874,8 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
||||
);
|
||||
}
|
||||
|
||||
const MemoBidLog = memo(BidLog);
|
||||
|
||||
export default function AuctionPage() {
|
||||
const { id } = useParams();
|
||||
const location = useLocation();
|
||||
@@ -814,7 +938,7 @@ export default function AuctionPage() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
||||
const timer = window.setInterval(() => setNow(Date.now()), 250);
|
||||
return () => window.clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
@@ -825,14 +949,28 @@ export default function AuctionPage() {
|
||||
|
||||
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
||||
const syncedNow = now + socket.serverTimeOffsetMs;
|
||||
const auctionState =
|
||||
liveAuction && matchQuery.data
|
||||
? mapApiAuctionToAuctionState(
|
||||
liveAuction,
|
||||
matchQuery.data,
|
||||
new Date(syncedNow),
|
||||
)
|
||||
: null;
|
||||
const baseAuctionState = useMemo(
|
||||
() =>
|
||||
liveAuction && matchQuery.data
|
||||
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data)
|
||||
: null,
|
||||
[liveAuction, matchQuery.data],
|
||||
);
|
||||
const auctionState = useMemo(() => {
|
||||
if (!baseAuctionState) return null;
|
||||
const deadlineTimestampMS = baseAuctionState.deadline
|
||||
? Date.parse(baseAuctionState.deadline)
|
||||
: undefined;
|
||||
const remainingMs =
|
||||
typeof deadlineTimestampMS === 'number' && Number.isFinite(deadlineTimestampMS)
|
||||
? Math.max(0, deadlineTimestampMS - syncedNow)
|
||||
: 0;
|
||||
return {
|
||||
...baseAuctionState,
|
||||
remainingMs,
|
||||
timer: Math.floor(remainingMs / 1000),
|
||||
};
|
||||
}, [baseAuctionState, syncedNow]);
|
||||
const availableTeamIndexes = useMemo(() => {
|
||||
const indexes = new Set((auctionState?.teams ?? []).map((team) => team.teamIndex));
|
||||
return [...indexes].sort((left, right) => left - right);
|
||||
@@ -915,6 +1053,9 @@ export default function AuctionPage() {
|
||||
const errorMessage =
|
||||
socket.error ??
|
||||
(auctionQuery.error instanceof Error ? auctionQuery.error.message : null);
|
||||
const bidLatencyMessage = formatBidLatencyDiagnostics(
|
||||
socket.bidLatencyDiagnostics,
|
||||
);
|
||||
const matchSideEffectMessage = resolveMatchSideEffectMessage(
|
||||
auctionState.matchSideEffectStatus,
|
||||
);
|
||||
@@ -1040,6 +1181,12 @@ export default function AuctionPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{import.meta.env.DEV && canManageAuction && bidLatencyMessage && (
|
||||
<div className="mb-4 border border-base-content/10 bg-base-100 px-4 py-2 text-xs text-base-content/45">
|
||||
입찰 계측 · {bidLatencyMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{undoMutation.error instanceof Error && (
|
||||
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
|
||||
{undoMutation.error.message}
|
||||
@@ -1116,12 +1263,12 @@ export default function AuctionPage() {
|
||||
|
||||
<div className="grid grid-cols-1 xl:grid-cols-[260px_minmax(0,1fr)_minmax(340px,440px)_320px] gap-4 mt-4">
|
||||
<aside className="hidden xl:block">
|
||||
<PoolPanel state={auctionState} />
|
||||
<MemoPoolPanel state={auctionState} />
|
||||
</aside>
|
||||
|
||||
<div className="grid sm:grid-cols-2 gap-4 content-start">
|
||||
{auctionState.teams.map((team) => (
|
||||
<TeamPanel
|
||||
<MemoTeamPanel
|
||||
key={team.teamIndex}
|
||||
team={team}
|
||||
isActive={isCurrentBidder(auctionState.currentBidder, team)}
|
||||
@@ -1157,7 +1304,7 @@ export default function AuctionPage() {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<PlayerSpotlight
|
||||
<MemoPlayerSpotlight
|
||||
state={auctionState}
|
||||
historyBackTo={historyBackTo}
|
||||
/>
|
||||
@@ -1184,7 +1331,7 @@ export default function AuctionPage() {
|
||||
})
|
||||
}
|
||||
/>
|
||||
<BidLog bids={auctionState.bids} />
|
||||
<MemoBidLog bids={auctionState.bids} />
|
||||
|
||||
{canManageAuction && (
|
||||
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
||||
@@ -1470,6 +1617,17 @@ function PoolPanel({ state }: { state: AuctionStateView }) {
|
||||
);
|
||||
}
|
||||
|
||||
const MemoPoolPanel = memo(
|
||||
PoolPanel,
|
||||
(previous, next) =>
|
||||
previous.state.phase === next.state.phase &&
|
||||
previous.state.currentPlayerIndex === next.state.currentPlayerIndex &&
|
||||
previous.state.currentPlayer?.userId === next.state.currentPlayer?.userId &&
|
||||
previous.state.auctionOrder === next.state.auctionOrder &&
|
||||
previous.state.passedQueue === next.state.passedQueue &&
|
||||
previous.state.teams === next.state.teams,
|
||||
);
|
||||
|
||||
function PoolTabButton({
|
||||
label,
|
||||
count,
|
||||
|
||||
Reference in new issue
Block a user