diff --git a/README.md b/README.md index 38131e046..b01275190 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ We added some options: * **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!) +* **experiment_enable_chat_access_hash_cleanup** (true/false) During cleanup, clean chats and channels access hash (Experimental!) ## Custom API functions ### TdApi.OptimizeMemory diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1cf9605c5..50385dda7 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -14685,6 +14685,7 @@ void ContactsManager::memory_cleanup() { auto user_ttl = !G()->shared_config().get_option_integer("delete_user_reference_after_seconds", 3600); auto chat_ttl = !G()->shared_config().get_option_integer("delete_chat_reference_after_seconds", 3600); + auto chat_access_hash_cleanup = !G()->shared_config().get_option_boolean("experiment_enable_chat_access_hash_cleanup", false); /* DESTROY INVALID USERS */ { @@ -14719,59 +14720,65 @@ void ContactsManager::memory_cleanup() { my_photo_file_id_.clear(); my_photo_file_id_.rehash(0); - /* DESTROY INVALID CHATS */ - { - auto it = chats_.begin(); - while (it != chats_.end()) { - //auto &chat = it->second; - auto chat_id = it->first; + if (chat_access_hash_cleanup) { + /* DESTROY INVALID CHATS */ + { + auto it = chats_.begin(); + while (it != chats_.end()) { + //auto &chat = it->second; + auto chat_id = it->first; - auto is_invalid = time - chat_id.get_time() > chat_ttl; + auto is_invalid = time - chat_id.get_time() > chat_ttl; - if (is_invalid) { - chat_id.reset_time(); - it = chats_.erase(it); - } else { - it++; + if (is_invalid) { + chat_id.reset_time(); + it = chats_.erase(it); + } else { + it++; + } } } - } - chats_.rehash(0); + 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); + if (chat_access_hash_cleanup) { + chat_full_file_source_ids_.clear(); + chat_full_file_source_ids_.rehash(0); + min_channels_.clear(); + min_channels_.rehash(0); - /* DESTROY INVALID CHANNELS */ - { - auto it = channels_.begin(); - while (it != channels_.end()) { - //auto &channel = it->second; - auto channel_id = it->first; + /* DESTROY INVALID CHANNELS */ + { + auto it = channels_.begin(); + while (it != channels_.end()) { + //auto &channel = it->second; + auto channel_id = it->first; - auto is_invalid = time - channel_id.get_time() > chat_ttl; + auto is_invalid = time - channel_id.get_time() > chat_ttl; - if (is_invalid) { - channel_id.reset_time(); - it = channels_.erase(it); - } else { - it++; + if (is_invalid) { + channel_id.reset_time(); + it = channels_.erase(it); + } else { + it++; + } } } - } - channels_.rehash(0); - channels_full_.clear(); - channels_full_.rehash(0); + 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); + if (chat_access_hash_cleanup) { + channel_full_file_source_ids_.clear(); + channel_full_file_source_ids_.rehash(0); + } //secret_chats_.clear(); //secret_chats_.rehash(0); //unknown_secret_chats_.clear(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9d3a2a151..8c80b1d2d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7345,6 +7345,9 @@ void Td::on_request(uint64 id, td_api::setOption &request) { if (set_boolean_option("experiment_debug_file_reference_cleanup")) { return; } + if (set_boolean_option("experiment_enable_chat_access_hash_cleanup")) { + return; + } break; case 'i': if (set_boolean_option("ignore_background_updates")) {