perf: use channel.purge() instead of per-message delete loops (#93) #108
No reviewers
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#108
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/major-domo-v2#93"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #93
Summary
Replace sequential
message.delete()loops withchannel.purge()bulk delete in three locations:commands/admin/management.py—admin_clear_scorecards: was up to 100 individual API calls; now 1tasks/live_scorebug_tracker.py—_post_scorebugs_to_channel: was up to 25 individual deletes on every 3-minute cycle; now 1tasks/live_scorebug_tracker.py—_clear_live_scores_channel: same as abovechannel.purge()uses Discord's bulk delete endpoint which handles up to 100 messages per request. Messages in the scorebug channel and live-scores channel are always recent (seconds to minutes old), well within the 14-day bulk delete limit.Test results
935 passed, 2 skipped (18 pre-existing failures from unrelated working-tree modifications — confirmed baseline, not introduced by this PR)
Review: perf: use channel.purge() instead of per-message delete loops
Verdict: APPROVED (posted as COMMENT — Gitea blocks self-approval)
What was reviewed
Three
history()+ per-messagedelete()loops replaced withchannel.purge()in:commands/admin/management.py—admin_clear_scorecards(limit=100)tasks/live_scorebug_tracker.py—_post_scorebugs_to_channel(limit=25)tasks/live_scorebug_tracker.py—_clear_live_scores_channel(limit=25)Plus a cosmetic trailing-comma reformat on the
read_scorebug_datacall (no behavioral effect).Findings
Correctness — no issues.
All three changes are semantically equivalent on the success path. Specific checks:
management.pyNotFoundhandling: The old innertry/except discord.NotFound: passis removed. This is correct —channel.purge()handles 404s internally per message (discord.py discards not-found messages during bulk delete). No regression.deleted_messages = await live_scores_channel.purge(...)→len(deleted_messages)correctly maintains thedeleted_countused in the success embed. The two tracker methods discard the return value, which is correct (they logged a fixed string, not a count).except discord.Forbidden+except Exceptionwrappers that survive unchanged. Permissions failures produce user-facing messages inmanagement.pyand structured logs in the tracker.Minor note — permission dependency shift (no action required, informational):
channel.purge()internally callschannel.delete_messages()(the Discord bulk-delete endpoint), which requiresMANAGE_MESSAGES. The old per-messagemessage.delete()on the bot's own messages does not requireMANAGE_MESSAGES— only message ownership. In practice the bot certainly hasMANAGE_MESSAGESin a channel it manages, so this is a very low-risk behavioural note. If it ever became a problem, it would fail withForbidden(already caught).Test results
935 passed, 2 skipped, 18 pre-existing failures (unrelated working-tree modifications — confirmed baseline, not introduced by this PR).
Mergeable: true. No blocking issues.