Audio config optimization #5408
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 milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5408
Loading…
Reference in a new issue
No description provided.
Delete branch "audio_config_optimization"
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
Sums up config calls in core audio by using .all()
Gets rid of guild_from_id wherever possible
Some config things I noticed while writing #5389. Currently, audio uses .all occasionally but sometimes also does multiple single config calls in a row. Sometimes even both combined in a single command. This PR fixes that
@ -40,3 +43,4 @@)player = lavalink.get_player(ctx.guild.id)can_skip = await self._can_instaskip(ctx, ctx.author)if (These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
I'm pretty sure you wanted to switch to call to
all()here:I'm pretty sure you wanted to switch to call to
all()here:If we already know that the ID isn't in cache, we don't need to use
setdefault():If we already know that the ID isn't in cache, we don't need to use
setdefault():These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
If we already know that the ID isn't in cache, we don't need to use
setdefault():These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
typo
If we already know that the ID isn't in cache, we don't need to use
setdefault():@ -1477,3 +1479,4 @@dj_enabled = self._dj_status_cache.setdefault(ctx.guild.id, guild_data["dj_enabled"])if dj_enabled and not await self._can_instaskip(ctx, ctx.author):ctx.command.reset_cooldown(ctx)await self.send_embed_msg(These are unnecessary changes to the code logic, let's just keep it as similar to the original code as possible since this PR is meant for config optimizations, not moving code around (especially when the reason for this moving is unknown).
More information about why those changes were made can be found at: https://discord.com/channels/133049272517001216/171665724262055936/902639810294988881
For clarity I will repeat some of what I said in the convo at that link when I partially reviewed these changes in that discussion without commenting on this issue:
Instead of
Change it to:
2 - Keep guild_from_id as is as it serves as a demo example for newcomers and that's what core cogs are supposed to do in my opinion
3 - Be considerate of .all() calls as they can be expensive, especially on larger bots
3.1 - Sometimes 2 config calls is cheaper than an .all() so if a command has early exits that's likely why .all() wasnt used on it... as making an expensive .all() call would be a waste of resources and potentially slow the bot down (like a user spamming [p]repeat when DJ mode is enabled)
Jack, if you want changes like the example here done in another PR that's understandable and I don't need to fight against it, this comment is for providing clarity on why changes like this were added to this PR.
While I was talking with @Drapersniper about these changes and setdefault, he said this to me:
The idea behind dj_enabled here is to cache is in an attribute
and NEVER call config for it if its in the cache
his "improvement" here calls .all()
which means its always calling the dj_attribute
while i say this
this right now is broken in audio
because of the way setdefault works
so its not "broken" but its for behaving as intended
the idea here is self._dj_status_cache.setdefault will only call await self.config.guild(ctx.guild).dj_enabled() if the cache for this guild is empty
but thats not how setdefault works unfortunately
which means await self.config.guild(ctx.guild).dj_enabled() ALWAYS gets called
It's been over 4 years since the last changes on this PR were made, and there are still unresolved review comments on this PR. It's time to just close this.
Pull request closed