Update ContactsManager.cpp, StickersManager.cpp, and WebPagesManager.cpp

This commit is contained in:
Andrea Cavalli 2020-07-31 15:51:49 +02:00
parent e2947da564
commit aae28b4fb5
3 changed files with 89 additions and 24 deletions

View File

@ -14342,36 +14342,64 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
}
void ContactsManager::memory_cleanup() {
users_.clear();
users_.rehash(0);
users_full_.clear();
users_full_.rehash(0);
bot_infos_.clear();
bot_infos_.rehash(0);
user_photos_.clear();
user_photos_.rehash(0);
unknown_users_.clear();
unknown_users_.rehash(0);
user_profile_photo_file_source_ids_.clear();
user_profile_photo_file_source_ids_.rehash(0);
my_photo_file_id_.clear();
my_photo_file_id_.rehash(0);
chats_.clear();
chats_.rehash(0);
chats_full_.clear();
chats_full_.rehash(0);
unknown_chats_.clear();
unknown_chats_.rehash(0);
chat_full_file_source_ids_.clear();
chat_full_file_source_ids_.rehash(0);
min_channels_.clear();
min_channels_.rehash(0);
channels_.clear();
channels_.rehash(0);
channels_full_.clear();
channels_full_.rehash(0);
unknown_channels_.clear();
unknown_channels_.rehash(0);
channel_full_file_source_ids_.clear();
channel_full_file_source_ids_.rehash(0);
secret_chats_.clear();
secret_chats_.rehash(0);
unknown_secret_chats_.clear();
unknown_secret_chats_.rehash(0);
secret_chats_with_user_.clear();
secret_chats_with_user_.rehash(0);
dialog_invite_links_.clear();
dialog_invite_links_.rehash(0);
invite_link_infos_.clear();
invite_link_infos_.rehash(0);
load_user_from_database_queries_.clear();
load_user_from_database_queries_.rehash(0);
load_chat_from_database_queries_.clear();
load_chat_from_database_queries_.rehash(0);
load_channel_from_database_queries_.clear();
load_channel_from_database_queries_.rehash(0);
load_secret_chat_from_database_queries_.clear();
load_secret_chat_from_database_queries_.rehash(0);
dialog_access_by_invite_link_.clear();
dialog_access_by_invite_link_.rehash(0);
loaded_from_database_users_.clear();
loaded_from_database_users_.rehash(0);
unavailable_user_fulls_.clear();
unavailable_user_fulls_.rehash(0);
unavailable_bot_infos_.clear();
unavailable_bot_infos_.rehash(0);
loaded_from_database_chats_.clear();
loaded_from_database_chats_.rehash(0);
unavailable_chat_fulls_.clear();
unavailable_chat_fulls_.rehash(0);
loaded_from_database_channels_.clear();
loaded_from_database_channels_.rehash(0);
loaded_from_database_secret_chats_.clear();
loaded_from_database_secret_chats_.rehash(0);
dialog_administrators_.clear();
dialog_administrators_.rehash(0);
uploaded_profile_photos_.clear();
@ -14384,7 +14412,17 @@ void ContactsManager::memory_cleanup() {
received_channel_participants_.rehash(0);
cached_channel_participants_.clear();
cached_channel_participants_.rehash(0);
found_blocked_users_.clear();
found_blocked_users_.rehash(0);
all_users_nearby_.clear();
all_users_nearby_.rehash(0);
linked_channel_ids_.clear();
linked_channel_ids_.rehash(0);
restricted_user_ids_.clear();
restricted_user_ids_.rehash(0);
restricted_channel_ids_.clear();
restricted_channel_ids_.rehash(0);
restricted_channel_ids_.clear();
restricted_channel_ids_.rehash(0);
}
} // namespace td

View File

@ -6302,16 +6302,6 @@ void StickersManager::memory_cleanup() {
found_sticker_sets_.rehash(0);
special_sticker_sets_.clear();
special_sticker_sets_.rehash(0);
sticker_set_load_requests_.clear();
sticker_set_load_requests_.rehash(0);
emoji_language_codes_.clear();
emoji_language_codes_.rehash(0);
emoji_language_code_versions_.clear();
emoji_language_code_versions_.rehash(0);
emoji_language_code_last_difference_times_.clear();
emoji_language_code_last_difference_times_.rehash(0);
emoji_suggestions_urls_.clear();
emoji_suggestions_urls_.rehash(0);
dice_messages_.clear();
dice_messages_.rehash(0);
}

View File

@ -540,7 +540,11 @@ void WebPagesManager::update_web_page(unique_ptr<WebPage> web_page, WebPageId we
return;
}
auto &page = web_pages_[web_page_id];
// Start custom-patches
auto find_page = web_pages_.find(web_page_id);
if (find_page == web_pages_.end()) { return; }
auto &page = find_page->second;
// End custom-patches
auto old_file_ids = get_web_page_file_ids(page.get());
WebPageInstantView old_instant_view;
bool is_changed = true;
@ -660,7 +664,12 @@ void WebPagesManager::on_get_web_page_instant_view_view_count(WebPageId web_page
return;
}
auto *instant_view = &web_pages_[web_page_id]->instant_view;
// Start custom-patches
auto find_web_page_val = web_pages_.find(web_page_id);
if (find_web_page_val == web_pages_.end()) { return; }
auto &web_page_val = find_web_page_val->second;
// End custom-patches
auto *instant_view = web_page_val->instant_view;
if (instant_view->is_empty) { return; }
if (instant_view->view_count >= view_count) {
return;
@ -674,7 +683,11 @@ void WebPagesManager::on_get_web_page_instant_view_view_count(WebPageId web_page
}
void WebPagesManager::on_get_web_page_by_url(const string &url, WebPageId web_page_id, bool from_database) {
auto &cached_web_page_id = url_to_web_page_id_[url];
// Start custom-patches
auto find_cached_web_page_id = url_to_web_page_id_.find(url);
if (find_cached_web_page_id == url_to_web_page_id_.end()) { return; }
auto &cached_web_page_id = find_cached_web_page_id->second;
// End custom-patches
if (!from_database && G()->parameters().use_message_db) {
if (web_page_id.is_valid()) {
if (cached_web_page_id != web_page_id) { // not already saved
@ -698,7 +711,12 @@ void WebPagesManager::register_web_page(WebPageId web_page_id, FullMessageId ful
}
LOG(INFO) << "Register " << web_page_id << " from " << full_message_id << " from " << source;
bool is_inserted = web_page_messages_[web_page_id].insert(full_message_id).second;
// Start custom-patches
auto find_web_page_message_ids = web_page_messages_.find(web_page_id);
if (find_web_page_message_ids == web_page_messages_.end()) { return; }
auto &web_page_message_ids = find_web_page_message_ids->second;
// End custom-patches
bool is_inserted = web_page_message_ids.insert(full_message_id).second;
if (!is_inserted) { return; }
if (!td_->auth_manager_->is_bot() && !have_web_page_force(web_page_id)) {
@ -713,7 +731,11 @@ void WebPagesManager::unregister_web_page(WebPageId web_page_id, FullMessageId f
}
LOG(INFO) << "Unregister " << web_page_id << " from " << full_message_id << " from " << source;
auto &message_ids = web_page_messages_[web_page_id];
// Start custom-patches
auto find_message_ids = web_page_messages_.find(web_page_id);
if (find_message_ids == web_page_messages_.end()) { return; }
auto &message_ids = find_message_ids->second;
// End custom-patches
auto is_deleted = message_ids.erase(full_message_id);
if (!is_deleted) {
return;
@ -1326,7 +1348,12 @@ void WebPagesManager::on_web_page_changed(WebPageId web_page_id, bool have_web_p
}
}
if (have_web_page) {
if (!(web_page_messages_[web_page_id].size() == full_message_ids.size())) { return; }
// Start custom-patches
auto find_web_page_message_ids = web_page_messages_.find(web_page_id);
if (find_web_page_message_ids == web_page_messages_.end()) { return; }
auto &web_page_message_ids = find_web_page_message_ids->second;
// End custom-patches
if (!(web_page_message_ids.size() == full_message_ids.size())) { return; }
} else {
if (!(web_page_messages_.count(web_page_id) == 0)) { return; }
}
@ -1683,8 +1710,16 @@ FileSourceId WebPagesManager::get_url_file_source_id(const string &url) {
const WebPage *web_page = get_web_page(web_page_id);
if (web_page != nullptr) {
if (!web_page->file_source_id.is_valid()) {
// Start custom-patches
auto find_web_page_val = web_pages_.find(web_page_id);
if (find_web_page_val != web_pages_.end()) {
auto &web_page_val = find_web_page_val->second;
// End custom-patches
web_pages_[web_page_id]->file_source_id =
td_->file_reference_manager_->create_web_page_file_source(web_page->url);
// Start custom-patches
}
// End custom-patches
}
return web_page->file_source_id;
}
@ -1723,6 +1758,8 @@ vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c
void WebPagesManager::memory_cleanup() {
web_pages_.clear();
web_pages_.rehash(0);
loaded_from_database_web_pages_.clear();
loaded_from_database_web_pages_.rehash(0);
web_page_messages_.clear();
web_page_messages_.rehash(0);
got_web_page_previews_.clear();