speed up connection speed a good bit

loading save state was slow so now theres a temporary lookup table
This commit is contained in:
ouwou 2021-12-31 16:42:06 -05:00
parent b576bd0fcc
commit 5338eab3a5
3 changed files with 22 additions and 10 deletions

View File

@ -388,7 +388,11 @@ void Abaddon::SaveState() {
}
void Abaddon::LoadState() {
if (!GetSettings().SaveState) return;
if (!GetSettings().SaveState) {
// call with empty data to purge the temporary table
m_main_window->GetChannelList()->UseExpansionState({});
return;
}
const auto data = ReadWholeFile(GetStateCachePath("/state.json"));
if (data.empty()) return;

View File

@ -1,11 +1,11 @@
#include "abaddon.hpp"
#include "channels.hpp"
#include "imgmanager.hpp"
#include "statusindicator.hpp"
#include "util.hpp"
#include <algorithm>
#include <map>
#include <unordered_map>
#include "abaddon.hpp"
#include "imgmanager.hpp"
#include "util.hpp"
#include "statusindicator.hpp"
ChannelList::ChannelList()
: Glib::ObjectBase(typeid(ChannelList))
@ -231,7 +231,6 @@ void ChannelList::UpdateChannel(Snowflake id) {
}
void ChannelList::UpdateCreateChannel(const ChannelData &channel) {
;
if (channel.Type == ChannelType::GUILD_CATEGORY) return (void)UpdateCreateChannelCategory(channel);
if (channel.Type == ChannelType::DM || channel.Type == ChannelType::GROUP_DM) return UpdateCreateDMChannel(channel);
if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return;
@ -378,11 +377,11 @@ void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
auto recurse = [this](auto &self, const ExpansionStateRoot &root) -> void {
// and these are only channels
for (const auto &[id, state] : root.Children) {
if (const auto iter = GetIteratorForChannelFromID(id)) {
if (const auto iter = m_tmp_channel_map.find(id); iter != m_tmp_channel_map.end()) {
if (state.IsExpanded)
m_view.expand_row(m_model->get_path(iter), false);
m_view.expand_row(m_model->get_path(iter->second), false);
else
m_view.collapse_row(m_model->get_path(iter));
m_view.collapse_row(m_model->get_path(iter->second));
}
self(self, state.Children);
@ -400,6 +399,8 @@ void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
recurse(recurse, state.Children);
}
m_tmp_channel_map.clear();
}
ExpansionStateRoot ChannelList::GetExpansionState() const {
@ -480,7 +481,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
if (it == threads.end()) return;
for (const auto &thread : it->second)
CreateThreadRow(row.children(), thread);
m_tmp_channel_map[thread.ID] = CreateThreadRow(row.children(), thread);
};
for (const auto &channel : orphan_channels) {
@ -491,6 +492,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset;
channel_row[m_columns.m_nsfw] = channel.NSFW();
add_threads(channel, channel_row);
m_tmp_channel_map[channel.ID] = channel_row;
}
for (const auto &[category_id, channels] : categories) {
@ -502,6 +504,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
cat_row[m_columns.m_name] = Glib::Markup::escape_text(*category->Name);
cat_row[m_columns.m_sort] = *category->Position;
cat_row[m_columns.m_expanded] = true;
m_tmp_channel_map[category_id] = cat_row;
// m_view.expand_row wont work because it might not have channels
for (const auto &channel : channels) {
@ -512,6 +515,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
channel_row[m_columns.m_sort] = *channel.Position;
channel_row[m_columns.m_nsfw] = channel.NSFW();
add_threads(channel, channel_row);
m_tmp_channel_map[channel.ID] = channel_row;
}
}

View File

@ -120,6 +120,10 @@ protected:
bool m_updating_listing = false;
// (GetIteratorForChannelFromID is rather slow)
// only temporary since i dont want to worry about maintaining this map
std::unordered_map<Snowflake, Gtk::TreeModel::iterator> m_tmp_channel_map;
public:
typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select;
typedef sigc::signal<void, Snowflake> type_signal_action_guild_leave;