Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in member for calculating effective permissions #873

Conversation

schnapster
Copy link
Contributor

@schnapster schnapster commented Mar 24, 2021

Description:

Allow passing in a proper Member object into GuildChannel#getEffectivePermissions instead of just a SnowflakeId.

Justification:

This allows optimizations of rest requests in certain situations.
When the GUILDS intent is used, but not the GUILD_MEMBERS intent, calling getEffectivePermissions with just the SnowflakeId of the user will result in a REST request to fetch the member (but no other request, as the owner, role data, etc can be served from the entity cache). In some situations it is unnecessary to fetch the member from the API. A MessageCreateEvent contains a Member object for the author, so if we wanted to check their permissions, we could avoid that API request by passing that member object to getEffectivePermissions, reducing the amount of necessary API requests to 0.

Another smaller use case would be checking self permissions. At a large scale, with the GUILD_MEMBERS intent not enabled, a bot author might want to have the option to handle caching their self member objects outside the entity cache, to heuristically reduce API calls for certain non-critical self permissions checks.

@quanticc quanticc requested a review from darichey March 24, 2021 23:41
@darichey darichey added area/core Related to core module: events, entities, clients, specs enhancement Improvement over an existing feature labels Mar 25, 2021
@darichey
Copy link
Member

That makes sense. Ironically, I think throughout the public API, we opted to accept Snowflakes instead of entities exactly because we didn't want people to fetch an entity unnecessarily. In this case, that's misleading (and detrimental) because we fetch it internally anyways.

I would be in favor of deprecating the Snowflake overload for this method. We should also look for other methods that do something similar (I'm really not sure how to perform that search though).

@quanticc quanticc added this to the 3.2.0 M2 milestone Mar 25, 2021
@quanticc quanticc merged commit 721a4fc into Discord4J:master Mar 25, 2021
@schnapster schnapster deleted the allow-passing-member-for-effective-permissions branch May 2, 2021 17:40
@quanticc quanticc mentioned this pull request Sep 11, 2021
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Related to core module: events, entities, clients, specs enhancement Improvement over an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants