mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: optimize role manager cache getter (#11239)
Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user