Optimize_memory code cleanup, add more error messages in MessagesManager

This commit is contained in:
Andrea Cavalli 2021-01-05 02:37:34 +01:00
parent 1430d6ec7b
commit 934c13ca79
2 changed files with 22 additions and 14 deletions

View File

@ -380,30 +380,34 @@ void FileReferenceManager::memory_cleanup() {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup begin"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup begin";
// Iterate all file sources and delete the unused ones
auto file_source_it = file_sources_.begin(); auto file_source_it = file_sources_.begin();
while (file_source_it != file_sources_.end()) { while (file_source_it != file_sources_.end()) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop begin"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop begin";
auto source_id = file_source_it->first; auto source_id = file_source_it->first;
// Mark immediately the file source as unused
auto file_source_unused = true;
// Iterate all the file nodes while the source is unused
auto file_nodes_it = nodes_.begin(); auto file_nodes_it = nodes_.begin();
auto remove = true; while (file_nodes_it != nodes_.end() && file_source_unused) {
while (file_nodes_it != nodes_.end() && remove) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop begin"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop begin";
// Get all the file sources related to the current file node
auto elements = get_all_file_sources(file_nodes_it->first); auto elements = get_all_file_sources(file_nodes_it->first);
auto elements_it = elements.begin();
while (elements_it != elements.end()) { // Iterate all the file sources related to the current file node
auto elements_it = elements.begin();
while (elements_it != elements.end() && file_source_unused) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop begin"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop begin";
if (source_id == (u_long) elements_it->get()) { if (source_id == (u_long) elements_it->get()) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop break"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop break";
remove = false; file_source_unused = false;
break; } else {
}
elements_it++; elements_it++;
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop next"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop next";
} }
}
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop end"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop end";
file_nodes_it++; file_nodes_it++;
@ -411,7 +415,7 @@ void FileReferenceManager::memory_cleanup() {
} }
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop end"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop end";
if (remove) { if (file_source_unused) {
if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> remove element from file_source"; if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> remove element from file_source";
file_source_it = file_sources_.erase(file_source_it); file_source_it = file_sources_.erase(file_source_it);
} else { } else {

View File

@ -6381,6 +6381,7 @@ void MessagesManager::add_pending_update(tl_object_ptr<telegram_api::Update> &&u
LOG(INFO) << "Save pending update got while running getDifference from " << source; LOG(INFO) << "Save pending update got while running getDifference from " << source;
if (td_->updates_manager_->running_get_difference()) { if (td_->updates_manager_->running_get_difference()) {
if (!(update->get_id() == dummyUpdate::ID || update->get_id() == updateSentMessage::ID)) { if (!(update->get_id() == dummyUpdate::ID || update->get_id() == updateSentMessage::ID)) {
LOG(ERROR) << "Failed CHECK(\"update->get_id() == dummyUpdate::ID || update->get_id() == updateSentMessage::ID\"). Postponed pts size: " << postponed_pts_updates_.size();
return; return;
} }
} }
@ -22255,7 +22256,10 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
return; return;
} }
auto d = get_dialog(dialog_id); auto d = get_dialog(dialog_id);
if (d == nullptr) { return; } if (d == nullptr) {
LOG(ERROR) << "Dialog == nullptr in \"on_get_scheduled_messages_from_database\"";
return;
}
d->has_loaded_scheduled_messages_from_database = true; d->has_loaded_scheduled_messages_from_database = true;
LOG(INFO) << "Receive " << messages.size() << " scheduled messages from database in " << dialog_id; LOG(INFO) << "Receive " << messages.size() << " scheduled messages from database in " << dialog_id;