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

GuildMember:getRoles() sorting #324

Open
RiskoZoSlovenska opened this issue Nov 9, 2021 · 0 comments
Open

GuildMember:getRoles() sorting #324

RiskoZoSlovenska opened this issue Nov 9, 2021 · 0 comments

Comments

@RiskoZoSlovenska
Copy link
Contributor

Currently, there is no easy way to get a sorted list of user's roles, despite the fact that GuildMember internally sorts the list of roles to get the role for :getHighestRole() and :getColor(). This Issue is actually two issues:

  1. It would be nice for GuildMember to provide a method to get a sorted list of roles.
  2. :getHighestRole() and :getColor() are doing unnecessary work when they sort the whole list (sorting is of O(n log n) complexity) just to get the highest role, for which a simple linear pass would work.

Just an idea here, but considering that :getRoles() (and thus all related functions) reference the role cache, a possible solution could be to have the cache always sorted (or always sort the result of State:getGuildRoles()), which would solve both problems.


For reference, my original comment from the community Discord server:

Yet another 3.0 suggestion: have GuildMember:getRoles() sort the roles according to their "height" from highest to lowest.
Reason: Having the list sorted can't hurt, and it's helpful for, say, printing out a list of a user's roles in order. The GuildMember class already has a local sorter defined that it uses for :getHighestRole() and :getColor() (also, what's the point of sorting the whole list (O(n log n) iirc) when a simple linear pass to get the highest role will suffice?), so implementing this should be trivial (heck, it could even go on and replace :getHighestRole()). Or maybe not have :getRoles() sort the list, but rather make a :getRolesSorted() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant