perf: use channel.purge() instead of per-message delete loops (#93)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m16s
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m16s
Closes #93 Replace sequential message.delete() loops with channel.purge() bulk delete in three locations: - commands/admin/management.py: admin_clear_scorecards (up to 100 msgs) - tasks/live_scorebug_tracker.py: _post_scorebugs_to_channel (25 msgs) - tasks/live_scorebug_tracker.py: _clear_live_scores_channel (25 msgs) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6c49233392
commit
8878ce85f7
@ -568,14 +568,9 @@ class AdminCommands(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Clear all messages from the channel
|
# Clear all messages from the channel using bulk delete
|
||||||
deleted_count = 0
|
deleted_messages = await live_scores_channel.purge(limit=100)
|
||||||
async for message in live_scores_channel.history(limit=100):
|
deleted_count = len(deleted_messages)
|
||||||
try:
|
|
||||||
await message.delete()
|
|
||||||
deleted_count += 1
|
|
||||||
except discord.NotFound:
|
|
||||||
pass # Message already deleted
|
|
||||||
|
|
||||||
self.logger.info(f"Cleared {deleted_count} messages from #live-sba-scores")
|
self.logger.info(f"Cleared {deleted_count} messages from #live-sba-scores")
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,8 @@ class LiveScorebugTracker:
|
|||||||
for text_channel_id, sheet_url in all_scorecards:
|
for text_channel_id, sheet_url in all_scorecards:
|
||||||
try:
|
try:
|
||||||
scorebug_data = await self.scorebug_service.read_scorebug_data(
|
scorebug_data = await self.scorebug_service.read_scorebug_data(
|
||||||
sheet_url, full_length=False # Compact view for live channel
|
sheet_url,
|
||||||
|
full_length=False, # Compact view for live channel
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only include active (non-final) games
|
# Only include active (non-final) games
|
||||||
@ -188,9 +189,8 @@ class LiveScorebugTracker:
|
|||||||
embeds: List of scorebug embeds
|
embeds: List of scorebug embeds
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Clear old messages
|
# Clear old messages using bulk delete
|
||||||
async for message in channel.history(limit=25):
|
await channel.purge(limit=25)
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
# Post new scorebugs (Discord allows up to 10 embeds per message)
|
# Post new scorebugs (Discord allows up to 10 embeds per message)
|
||||||
if len(embeds) <= 10:
|
if len(embeds) <= 10:
|
||||||
@ -216,9 +216,8 @@ class LiveScorebugTracker:
|
|||||||
channel: Discord text channel
|
channel: Discord text channel
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Clear all messages
|
# Clear all messages using bulk delete
|
||||||
async for message in channel.history(limit=25):
|
await channel.purge(limit=25)
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
self.logger.info("Cleared live-sba-scores channel (no active games)")
|
self.logger.info("Cleared live-sba-scores channel (no active games)")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user