perf(Role): linear speed position getter (#9493)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Aura Román 2023-05-05 14:49:00 +02:00 committed by GitHub
parent d4f12e0a0c
commit 8e9a2b4630
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,8 +188,14 @@ class Role extends Base {
* @readonly
*/
get position() {
const sorted = this.guild._sortedRoles();
return [...sorted.values()].indexOf(sorted.get(this.id));
return this.guild.roles.cache.reduce(
(acc, role) =>
acc +
(this.rawPosition === role.rawPosition
? BigInt(this.id) > BigInt(role.id)
: this.rawPosition > role.rawPosition),
0,
);
}
/**