speed up channel list population on connect a good bit

This commit is contained in:
ouwou
2023-01-21 00:57:09 -05:00
parent acb03642c2
commit dc7047265f
3 changed files with 53 additions and 9 deletions

View File

@@ -341,12 +341,10 @@ bool DiscordClient::HasChannelPermission(Snowflake user_id, Snowflake channel_id
}
Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guild_id) const {
const auto member = GetMember(member_id, guild_id);
const auto guild = GetGuild(guild_id);
if (!member.has_value() || !guild.has_value())
return Permission::NONE;
const auto member_roles = m_store.GetMemberRoles(guild_id, member_id);
const auto guild_owner = m_store.GetGuildOwner(guild_id);
if (guild->OwnerID == member_id)
if (guild_owner == member_id)
return Permission::ALL;
const auto everyone = GetRole(guild_id);
@@ -354,7 +352,7 @@ Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guil
return Permission::NONE;
Permission perms = everyone->Permissions;
for (const auto role_id : member->Roles) {
for (const auto role_id : member_roles) {
const auto role = GetRole(role_id);
if (role.has_value())
perms |= role->Permissions;
@@ -371,8 +369,8 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
return Permission::ALL;
const auto channel = GetChannel(channel_id);
const auto member = GetMember(member_id, *channel->GuildID);
if (!member.has_value() || !channel.has_value())
const auto member_roles = m_store.GetMemberRoles(*channel->GuildID, member_id);
if (!channel.has_value())
return Permission::NONE;
Permission perms = base;
@@ -384,7 +382,7 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
Permission allow = Permission::NONE;
Permission deny = Permission::NONE;
for (const auto role_id : member->Roles) {
for (const auto role_id : member_roles) {
const auto overwrite = GetPermissionOverwrite(channel_id, role_id);
if (overwrite.has_value()) {
allow |= overwrite->Allow;