diff --git a/README.md b/README.md index a31e9d02b..2f66ba2c4 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ We added some options: * **receive_access_hashes** (true/**false**) Receive chats and users access hash as updates * **experiment_enable_file_reference_cleanup** (**true**/false) During cleanup, free the memory of the file references * **experiment_enable_chat_access_hash_cleanup** (**true**/false) During cleanup, clean chats and channels access hash -* **enable_reactive_pull_backpressure** (true/**false**) Enable manual `get_channel_difference` execution by calling `getChannelDifference(channel_difference_id)`. - Don't modify this option unless you have a very large bot that struggles to keep up with start-up updates throughput, or you want to implement a backpressure-aware pull-based library. +* **enable_reactive_channel_difference** (true/**false**) Enable manual `get_channel_difference` execution by calling `getChannelDifference(channel_difference_id)`. + Don't modify this option unless you have a very large bot that struggles to keep up with start-up updates throughput, or you want to use a reactive library. ## Custom API functions ### TdApi.OptimizeMemory diff --git a/manual_checks.md b/manual_checks.md index c4709e398..7f95ea6a9 100644 --- a/manual_checks.md +++ b/manual_checks.md @@ -12,12 +12,12 @@ should become ```cpp - auto enable_reactive_pull_backpressure + auto enable_reactive_channel_difference = G()->shared_config() - .get_option_boolean("enable_reactive_pull_backpressure", false); + .get_option_boolean("enable_reactive_channel_difference", false); get_channel_difference_delayed(dialog_id, old_pts, true, - enable_reactive_pull_backpressure, + enable_reactive_channel_difference, "add_pending_channel_update pts mismatch"); ``` diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 594d730ba..7e40a49f5 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -938,6 +938,12 @@ void BackgroundManager::on_reset_background(Result &&result, Promise if (result.is_error()) { return promise.set_error(result.move_as_error()); } + reset_backgrounds_data(); + + promise.set_value(Unit()); +} + +void BackgroundManager::reset_backgrounds_data() { installed_backgrounds_.clear(); set_background_id(BackgroundId(), BackgroundType(), false); set_background_id(BackgroundId(), BackgroundType(), true); @@ -949,8 +955,6 @@ void BackgroundManager::on_reset_background(Result &&result, Promise local_background_ids_[1].clear(); save_local_backgrounds(true); } - - promise.set_value(Unit()); } void BackgroundManager::add_background(const Background &background, bool replace_type) { @@ -1056,7 +1060,7 @@ string BackgroundManager::get_background_name_database_key(const string &name) { std::pair BackgroundManager::on_get_background( BackgroundId expected_background_id, const string &expected_background_name, telegram_api::object_ptr wallpaper_ptr, bool replace_type) { - if (!(wallpaper_ptr != nullptr)) return BackgroundId(); + if (!(wallpaper_ptr != nullptr)) return {}; if (wallpaper_ptr->get_id() == telegram_api::wallPaperNoFile::ID) { auto wallpaper = move_tl_object_as(wallpaper_ptr); @@ -1282,7 +1286,7 @@ void BackgroundManager::memory_cleanup(bool full) { file_id_to_background_id_.rehash(0); loaded_from_database_backgrounds_.clear(); loaded_from_database_backgrounds_.rehash(0); - installed_background_ids_.clear(); + reset_backgrounds_data(); } void BackgroundManager::memory_stats(vector &output) { @@ -1296,7 +1300,7 @@ void BackgroundManager::memory_stats(vector &output) { output.push_back(","); output.push_back("\"loaded_from_database_backgrounds_\":"); output.push_back(std::to_string(loaded_from_database_backgrounds_.size())); output.push_back(","); - output.push_back("\"installed_background_ids_\":"); output.push_back(std::to_string(installed_background_ids_.size())); + output.push_back("\"installed_backgrounds_\":"); output.push_back(std::to_string(installed_backgrounds_.size())); } } // namespace td diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index c0c9f4395..30e732bcf 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -150,6 +150,8 @@ class BackgroundManager final : public Actor { void on_reset_background(Result &&result, Promise &&promise); + void reset_backgrounds_data(); + void upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme, Promise &&promise); void on_upload_background_file(FileId file_id, tl_object_ptr input_file); diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5bf80c882..b21415340 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -15850,6 +15850,8 @@ tl_object_ptr ContactsManager::get_user_access_hash_object(U tl_object_ptr type = make_tl_object(); DialogId dialog_id(user_id); return make_tl_object(dialog_id.get(), std::move(type), u->access_hash); + } else { + return nullptr; } } @@ -15861,6 +15863,8 @@ tl_object_ptr ContactsManager::get_channel_access_hash_objec tl_object_ptr type = make_tl_object(); DialogId dialog_id(channel_id); return make_tl_object(dialog_id.get(), std::move(type), c->access_hash); + } else { + return nullptr; } } @@ -16274,8 +16278,6 @@ void ContactsManager::memory_cleanup(bool full) { user_photos_.rehash(0); unknown_users_.clear(); unknown_users_.rehash(0); - pending_user_photos_.clear(); - pending_user_photos_.rehash(0); user_profile_photo_file_source_ids_.clear(); user_profile_photo_file_source_ids_.rehash(0); my_photo_file_id_.clear(); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 0b197dfcf..3e5180eee 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6936,16 +6936,16 @@ void MessagesManager::on_update_channel_too_long(tl_object_ptr d->pts) { - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "on_update_channel_too_long 1"); } } else { if (force_apply) { - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, -1, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, -1, true, enable_reactive_channel_difference, "on_update_channel_too_long 2"); } else { td_->updates_manager_->schedule_get_difference("on_update_channel_too_long 3"); @@ -7021,9 +7021,9 @@ void MessagesManager::update_message_interaction_info(FullMessageId full_message LOG(INFO) << "Ignore message interaction info about unknown " << full_message_id; if (!message_id.is_scheduled() && message_id > d->last_new_message_id && dialog_id.get_type() == DialogType::Channel) { - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "update_message_interaction_info"); } return; @@ -7599,9 +7599,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p LOG(INFO) << "Found a gap in unknown " << dialog_id << " with pts = " << pts << ". new_pts = " << new_pts << ", pts_count = " << pts_count << " in update from " << source; add_postponed_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise)); - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, pts, true, enable_reactive_pull_backpressure, "add_pending_channel_update 3"); + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, pts, true, enable_reactive_channel_difference, "add_pending_channel_update 3"); return; } @@ -7633,9 +7633,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p << ", update is from " << source << ": " << oneline(to_string(update)); last_channel_pts_jump_warning_time_ = now; } - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_pull_backpressure, "add_pending_channel_update old"); + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_channel_difference, "add_pending_channel_update old"); } if (update->get_id() == telegram_api::updateNewChannelMessage::ID) { @@ -7681,9 +7681,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p if (d->was_opened || td_->contacts_manager_->get_channel_status(channel_id).is_member() || is_dialog_sponsored(d)) { add_postponed_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise)); - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_channel_difference, "add_pending_channel_update pts mismatch"); } else { promise.set_value(Unit()); @@ -11497,9 +11497,9 @@ void MessagesManager::read_channel_message_content_from_updates(Dialog *d, Messa if (m != nullptr) { read_message_content(d, m, false, "read_channel_message_content_from_updates"); } else if (message_id > d->last_new_message_id) { - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(d->dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(d->dialog_id, d->pts, true, enable_reactive_channel_difference, "read_channel_message_content_from_updates"); } } @@ -14865,9 +14865,9 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vectorshared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "on_get_dialogs"); } } @@ -29462,9 +29462,9 @@ void MessagesManager::check_send_message_result(int64 random_id, DialogId dialog return; } if (dialog_id.get_type() == DialogType::Channel) { - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "check_send_message_result"); } else { td_->updates_manager_->schedule_get_difference("check_send_message_result"); @@ -33318,14 +33318,14 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq auto next_message = *it; if (next_message != nullptr) { if (next_message->message_id.is_server()) { - if (G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false) == false) { + if (G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false) == false) { LOG(ERROR) << "Attach " << message_id << " from " << source << " before " << next_message->message_id << " and after " << previous_message_id << " in " << dialog_id; dump_debug_message_op(d); } } } else { - if (G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false) == false) { + if (G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false) == false) { LOG(ERROR) << "Have_next is true, but there is no next message after " << previous_message_id << " from " << source << " in " << dialog_id; dump_debug_message_op(d); @@ -36421,9 +36421,10 @@ void MessagesManager::run_after_channel_difference(DialogId dialog_id, Promiseshared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d == nullptr ? load_channel_pts(dialog_id) : d->pts, true, enable_reactive_pull_backpressure, + const Dialog *d = get_dialog(dialog_id); + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d == nullptr ? load_channel_pts(dialog_id) : d->pts, true, enable_reactive_channel_difference, "run_after_channel_difference"); } @@ -36442,9 +36443,9 @@ void MessagesManager::on_channel_get_difference_timeout(DialogId dialog_id) { LOG(ERROR) << "Unknown dialog " << dialog_id; return; } - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "on_channel_get_difference_timeout"); } @@ -36474,8 +36475,8 @@ class MessagesManager::GetChannelDifferenceLogEvent { }; void MessagesManager::get_channel_difference_delayed(DialogId dialog_id, int32 pts, - bool force, bool enable_reactive_pull_backpressure, const char *source) { - if (!enable_reactive_pull_backpressure) { + bool force, bool enable_reactive_channel_difference, const char *source) { + if (!enable_reactive_channel_difference) { // Execute get_channel_difference immediatly const char* source_prefix = "on_get_channel_difference, "; char* joined_source{ new char[strlen(source_prefix) + strlen(source) + 1] }; @@ -37067,9 +37068,9 @@ void MessagesManager::on_get_channel_difference( if (!is_final) { LOG_IF(ERROR, timeout > 0) << "Have timeout in nonfinal ChannelDifference in " << dialog_id; - auto enable_reactive_pull_backpressure - = G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false); - get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, "on_get_channel_difference"); + auto enable_reactive_channel_difference + = G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false); + get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "on_get_channel_difference"); return; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 46cfe4463..00d73636e 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2898,7 +2898,7 @@ class MessagesManager final : public Actor { void on_channel_get_difference_timeout(DialogId dialog_id); - void get_channel_difference_delayed(DialogId dialog_id, int32 pts, bool force, bool enable_reactive_pull_backpressure, + void get_channel_difference_delayed(DialogId dialog_id, int32 pts, bool force, bool enable_reactive_channel_difference, const char *source); void get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source); diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index a83035114..4d6c3beec 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1737,8 +1737,6 @@ void PollManager::memory_cleanup(bool full) { polls_.rehash(0); poll_messages_.clear(); poll_messages_.rehash(0); - pending_answers_.clear(); - pending_answers_.rehash(0); poll_voters_.clear(); poll_voters_.rehash(0); loaded_from_database_polls_.clear(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 539fea887..282491d69 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7652,7 +7652,7 @@ void Td::on_request(uint64 id, td_api::setOption &request) { if (set_boolean_option("experiment_old_postponed_pts_updates_behavior")) { return; } - if (set_boolean_option("enable_reactive_pull_backpressure")) { + if (set_boolean_option("enable_reactive_channel_difference")) { return; } break;