cache channels

This commit is contained in:
ouwou
2020-12-10 03:50:40 -05:00
parent e045452875
commit 850b87c1ec
11 changed files with 330 additions and 204 deletions

View File

@@ -136,14 +136,14 @@ std::vector<Snowflake> Guild::GetSortedChannels(Snowflake ignore) const {
std::map<int, std::vector<const Channel *>> position_to_categories;
std::map<int, std::vector<const Channel *>> orphan_channels;
for (const auto &channel_id : channels) {
const auto *data = discord.GetChannel(channel_id);
if (data == nullptr) continue;
if (!data->ParentID.IsValid() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS))
orphan_channels[data->Position].push_back(data);
else if (data->ParentID.IsValid() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS))
category_to_channels[data->ParentID].push_back(data);
const auto data = discord.GetChannel(channel_id);
if (!data.has_value()) continue;
if (!data->ParentID->IsValid() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS))
orphan_channels[*data->Position].push_back(&*data);
else if (data->ParentID->IsValid() && (data->Type == ChannelType::GUILD_TEXT || data->Type == ChannelType::GUILD_NEWS))
category_to_channels[*data->ParentID].push_back(&*data);
else if (data->Type == ChannelType::GUILD_CATEGORY)
position_to_categories[data->Position].push_back(data);
position_to_categories[*data->Position].push_back(&*data);
}
for (auto &[pos, channels] : orphan_channels) {