[Help] Optimisation on getting commands in Cog-help #5354
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5354
Loading…
Reference in a new issue
No description provided.
Delete branch "help-optimise"
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?
Description of the changes
Now this PR might be nitpicky, but getting every command from the bot and filtering the cog commands when a cog help is requested is slower compared to using a default method (get_commands) provided by the cog.
This further saves a lot of overhead in
get_bot_help_mappingwhich requests theget_cog_help_mappingwith every loaded cog.In short, the bot used to get every command present in the bot again and again (and then filter it) for every cog loaded to display help. Now it's faster but simply getting the commands of the cog requested.
One possible downside (though I haven't tested it) is, This prevents monkey-patched/Commands created dynamically and the cog object injected into it, to not show up in the help. Tho such are forbidden methods to make commands I assume.
@ -274,7 +274,10 @@ class RedHelpFormatter(HelpFormatterABC):async def get_cog_help_mapping(This happens specifically because
Noneis passed to this method as a "cog" object to catch any commands with no cog associated with them when listing all commands in the bot. I don't know if there's any special way to get a list of commands not associated with a cog, so this might need to use the existing check in this case.github.com/Cog-Creators/Red-DiscordBot@aa51fd9ad1/redbot/core/commands/help.py (L295-L296)