perf: eliminate redundant API calls in trade views (#94)
Closes #94 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c30e0ad321
commit
8e984d1d07
@ -328,6 +328,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
def __init__(self, builder: TradeBuilder):
|
def __init__(self, builder: TradeBuilder):
|
||||||
super().__init__(timeout=3600.0) # 1 hour timeout
|
super().__init__(timeout=3600.0) # 1 hour timeout
|
||||||
self.builder = builder
|
self.builder = builder
|
||||||
|
self._checked_team: Optional[Team] = None
|
||||||
|
|
||||||
async def _get_user_team(self, interaction: discord.Interaction) -> Optional[Team]:
|
async def _get_user_team(self, interaction: discord.Interaction) -> Optional[Team]:
|
||||||
"""Get the team owned by the interacting user."""
|
"""Get the team owned by the interacting user."""
|
||||||
@ -353,6 +354,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self._checked_team = user_team
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def on_timeout(self) -> None:
|
async def on_timeout(self) -> None:
|
||||||
@ -366,7 +368,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
self, interaction: discord.Interaction, button: discord.ui.Button
|
self, interaction: discord.Interaction, button: discord.ui.Button
|
||||||
):
|
):
|
||||||
"""Handle accept button click."""
|
"""Handle accept button click."""
|
||||||
user_team = await self._get_user_team(interaction)
|
user_team = self._checked_team
|
||||||
if not user_team:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -401,7 +403,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
self, interaction: discord.Interaction, button: discord.ui.Button
|
self, interaction: discord.Interaction, button: discord.ui.Button
|
||||||
):
|
):
|
||||||
"""Handle reject button click - moves trade back to DRAFT."""
|
"""Handle reject button click - moves trade back to DRAFT."""
|
||||||
user_team = await self._get_user_team(interaction)
|
user_team = self._checked_team
|
||||||
if not user_team:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -708,10 +710,10 @@ async def create_trade_embed(builder: TradeBuilder) -> discord.Embed:
|
|||||||
Returns:
|
Returns:
|
||||||
Discord embed with current trade state
|
Discord embed with current trade state
|
||||||
"""
|
"""
|
||||||
|
validation = await builder.validate_trade()
|
||||||
if builder.is_empty:
|
if builder.is_empty:
|
||||||
color = EmbedColors.SECONDARY
|
color = EmbedColors.SECONDARY
|
||||||
else:
|
else:
|
||||||
validation = await builder.validate_trade()
|
|
||||||
color = EmbedColors.SUCCESS if validation.is_legal else EmbedColors.WARNING
|
color = EmbedColors.SUCCESS if validation.is_legal else EmbedColors.WARNING
|
||||||
|
|
||||||
embed = EmbedTemplate.create_base_embed(
|
embed = EmbedTemplate.create_base_embed(
|
||||||
@ -766,7 +768,6 @@ async def create_trade_embed(builder: TradeBuilder) -> discord.Embed:
|
|||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
validation = await builder.validate_trade()
|
|
||||||
if validation.is_legal:
|
if validation.is_legal:
|
||||||
status_text = "Trade appears legal"
|
status_text = "Trade appears legal"
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user