From 5686d574f842f74a21897faacb4425471a216cb0 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 4 Jan 2021 12:00:33 +0100 Subject: [PATCH] Add experimental options --- README.md | 2 ++ td/telegram/FileReferenceManager.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 641d24ca6..38131e046 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ We added some options: * **delete_chat_reference_after_seconds** (positive number) During cleanup, free the memory of the chats that have not been touched for more than X seconds * **delete_user_reference_after_seconds** (positive number) During cleanup, free the memory of the users that have not been touched for more than X seconds * **delete_file_reference_after_seconds** (positive number) During cleanup, free the memory of the files that have not been touched for more than X seconds +* **experiment_enable_file_reference_cleanup** (true/false) During cleanup, free the memory of the file references (Experimental!) +* **experiment_debug_file_reference_cleanup** (true/false) During cleanup, print log messages about file references cleanup (Experimental!) ## Custom API functions ### TdApi.OptimizeMemory diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index dff4e381f..1ac2e58a9 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -14,6 +14,7 @@ #include "td/telegram/MessagesManager.h" #include "td/telegram/StickerSetId.h" #include "td/telegram/StickersManager.h" +#include "td/telegram/ConfigShared.h" #include "td/telegram/Td.h" #include "td/telegram/WebPagesManager.h" @@ -372,35 +373,55 @@ void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise pr } void FileReferenceManager::memory_cleanup() { + if (!G()->shared_config().get_option_boolean("experiment_enable_file_reference_cleanup", false)) { + return; + } + auto print_debug_messages = G()->shared_config().get_option_boolean("experiment_debug_file_reference_cleanup", false); + + if (print_debug_messages) LOG(ERROR) << "memory_cleanup begin"; + auto file_source_it = file_sources_.begin(); while (file_source_it != file_sources_.end()) { + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop begin"; auto source_id = file_source_it->first; auto file_nodes_it = nodes_.begin(); auto remove = true; while (file_nodes_it != nodes_.end() && remove) { + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop begin"; auto elements = get_all_file_sources(file_nodes_it->first); auto elements_it = elements.begin(); while (elements_it != elements.end()) { + 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 (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop >> elements loop break"; remove = false; break; } 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 end"; file_nodes_it++; + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop next"; } + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop >> file_nodes loop end"; if (remove) { + 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); } else { file_source_it++; } + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop next"; } + if (print_debug_messages) LOG(ERROR) << "memory_cleanup >> file_source loop end"; + + if (print_debug_messages) LOG(ERROR) << "memory_cleanup end"; } void FileReferenceManager::memory_cleanup(NodeId node_id) {