feat: optimize role manager cache getter (#11239)

Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
Josef
2025-11-09 11:51:40 +01:00
committed by Jiralite
parent 1c5701651a
commit 2da2fa01b2
2 changed files with 20 additions and 3 deletions

View File

@@ -31,7 +31,15 @@ class GuildEmojiRoleManager extends DataManager {
* @readonly * @readonly
*/ */
get cache() { get cache() {
return this.guild.roles.cache.filter(role => this.emoji._roles.includes(role.id)); const cache = new Collection();
for (const roleId of this.emoji._roles) {
const role = this.guild.roles.cache.get(roleId);
if (role !== undefined) {
cache.set(roleId, role);
}
}
return cache;
} }
/** /**

View File

@@ -33,8 +33,17 @@ class GuildMemberRoleManager extends DataManager {
* @readonly * @readonly
*/ */
get cache() { get cache() {
const everyone = this.guild.roles.everyone; const cache = new Collection();
return this.guild.roles.cache.filter(role => this.member._roles.includes(role.id)).set(everyone.id, everyone); cache.set(this.guild.id, this.guild.roles.everyone);
for (const roleId of this.member._roles) {
const role = this.guild.roles.cache.get(roleId);
if (role !== undefined) {
cache.set(roleId, role);
}
}
return cache;
} }
/** /**