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:
Cal Corum 2026-03-20 13:33:03 -05:00
parent c30e0ad321
commit 8e984d1d07

View File

@ -328,6 +328,7 @@ class TradeAcceptanceView(discord.ui.View):
def __init__(self, builder: TradeBuilder):
super().__init__(timeout=3600.0) # 1 hour timeout
self.builder = builder
self._checked_team: Optional[Team] = None
async def _get_user_team(self, interaction: discord.Interaction) -> Optional[Team]:
"""Get the team owned by the interacting user."""
@ -353,6 +354,7 @@ class TradeAcceptanceView(discord.ui.View):
)
return False
self._checked_team = user_team
return True
async def on_timeout(self) -> None:
@ -366,7 +368,7 @@ class TradeAcceptanceView(discord.ui.View):
self, interaction: discord.Interaction, button: discord.ui.Button
):
"""Handle accept button click."""
user_team = await self._get_user_team(interaction)
user_team = self._checked_team
if not user_team:
return
@ -401,7 +403,7 @@ class TradeAcceptanceView(discord.ui.View):
self, interaction: discord.Interaction, button: discord.ui.Button
):
"""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:
return
@ -708,10 +710,10 @@ async def create_trade_embed(builder: TradeBuilder) -> discord.Embed:
Returns:
Discord embed with current trade state
"""
validation = await builder.validate_trade()
if builder.is_empty:
color = EmbedColors.SECONDARY
else:
validation = await builder.validate_trade()
color = EmbedColors.SUCCESS if validation.is_legal else EmbedColors.WARNING
embed = EmbedTemplate.create_base_embed(
@ -766,7 +768,6 @@ async def create_trade_embed(builder: TradeBuilder) -> discord.Embed:
inline=False,
)
validation = await builder.validate_trade()
if validation.is_legal:
status_text = "Trade appears legal"
else: