perf: eliminate redundant API calls in trade views (#94) #116
@ -344,6 +344,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_teams: dict[int, Team] = {}
|
||||||
|
|
||||||
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."""
|
||||||
@ -369,6 +370,7 @@ class TradeAcceptanceView(discord.ui.View):
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self._checked_teams[interaction.user.id] = user_team
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def on_timeout(self) -> None:
|
async def on_timeout(self) -> None:
|
||||||
@ -382,7 +384,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_teams.get(interaction.user.id)
|
||||||
if not user_team:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -417,7 +419,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_teams.get(interaction.user.id)
|
||||||
if not user_team:
|
if not user_team:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -733,10 +735,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(
|
||||||
@ -791,7 +793,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