From 367d3eaa2bd53a05bb242b678d42a8776b005d84 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Mar 2023 21:13:59 +0300 Subject: [PATCH] Move ignore_background_updates() to Td. --- td/telegram/Global.cpp | 4 ---- td/telegram/Global.h | 6 ------ td/telegram/MessagesManager.cpp | 10 +++++----- td/telegram/Td.cpp | 5 +++++ td/telegram/Td.h | 8 ++++++++ td/telegram/UpdatesManager.cpp | 10 +++++----- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 2b94bab5d..837274825 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -231,10 +231,6 @@ DcId Global::get_webfile_dc_id() const { return DcId::internal(dc_id); } -bool Global::ignore_background_updates() const { - return !parameters_.use_file_db && !parameters_.use_secret_chats && get_option_boolean("ignore_background_updates"); -} - void Global::set_net_query_stats(std::shared_ptr net_query_stats) { net_query_creator_.set_create_func( [net_query_stats = std::move(net_query_stats)] { return td::make_unique(net_query_stats); }); diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 3081d5373..ba0072487 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -110,8 +110,6 @@ class Global final : public ActorContext { return parameters_.use_test_dc; } - bool ignore_background_updates() const; - NetQueryCreator &net_query_creator() { return *net_query_creator_.get(); } @@ -408,10 +406,6 @@ class Global final : public ActorContext { return parameters_.use_message_db; } - bool use_secret_chats() const { - return parameters_.use_secret_chats; - } - int32 get_gc_scheduler_id() const { return gc_scheduler_id_; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ca544d831..1dd96dd4a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13733,7 +13733,7 @@ void MessagesManager::init() { main_dialog_list_position_ = 0; } - dialog_filters_updated_date_ = G()->ignore_background_updates() ? 0 : log_event.updated_date; + dialog_filters_updated_date_ = td_->ignore_background_updates() ? 0 : log_event.updated_date; std::unordered_set server_dialog_filter_ids; for (auto &dialog_filter : log_event.server_dialog_filters_out) { if (dialog_filter->dialog_filter_id.is_valid() && @@ -39428,7 +39428,7 @@ string MessagesManager::get_channel_pts_key(DialogId dialog_id) { } int32 MessagesManager::load_channel_pts(DialogId dialog_id) const { - if (G()->ignore_background_updates() || !have_input_peer(dialog_id, AccessRights::Read)) { + if (td_->ignore_background_updates() || !have_input_peer(dialog_id, AccessRights::Read)) { G()->td_db()->get_binlog_pmc()->erase(get_channel_pts_key(dialog_id)); // just in case return 0; } @@ -39479,7 +39479,7 @@ void MessagesManager::set_channel_pts(Dialog *d, int32 new_pts, const char *sour repair_channel_server_unread_count(d); } } - if (!G()->ignore_background_updates() && have_input_peer(d->dialog_id, AccessRights::Read)) { + if (!td_->ignore_background_updates() && have_input_peer(d->dialog_id, AccessRights::Read)) { G()->td_db()->get_binlog_pmc()->set(get_channel_pts_key(d->dialog_id), to_string(new_pts)); } } else if (new_pts < d->pts) { @@ -39595,7 +39595,7 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool return; } - if (force && get_channel_difference_to_log_event_id_.count(dialog_id) == 0 && !G()->ignore_background_updates()) { + if (force && get_channel_difference_to_log_event_id_.count(dialog_id) == 0 && !td_->ignore_background_updates()) { auto channel_id = dialog_id.get_channel_id(); CHECK(input_channel->get_id() == telegram_api::inputChannel::ID); auto access_hash = static_cast(*input_channel).access_hash_; @@ -41318,7 +41318,7 @@ void MessagesManager::on_binlog_events(vector &&events) { break; } case LogEvent::HandlerType::GetChannelDifference: { - if (G()->ignore_background_updates()) { + if (td_->ignore_background_updates()) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9e12a549e..b1fa321df 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2743,6 +2743,10 @@ void Td::set_is_bot_online(bool is_bot_online) { send_closure(G()->state_manager(), &StateManager::on_online, is_bot_online_); } +bool Td::ignore_background_updates() const { + return can_ignore_background_updates_ && option_manager_->get_option_boolean("ignore_background_updates"); +} + bool Td::is_authentication_request(int32 id) { switch (id) { case td_api::setTdlibParameters::ID: @@ -2962,6 +2966,7 @@ void Td::run_request(uint64 id, tl_object_ptr function) { VLOG(td_init) << "Begin to open database"; set_parameters_request_id_ = id; + can_ignore_background_updates_ = !r_parameters.ok().use_file_db && !r_parameters.ok().use_secret_chats; auto promise = PromiseCreator::lambda([actor_id = actor_id(this)](Result r_opened_database) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 997bce2d5..e022473b3 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -133,6 +133,12 @@ class Td final : public Actor { void set_is_bot_online(bool is_bot_online); + bool can_ignore_background_updates() const { + return can_ignore_background_updates_; + } + + bool ignore_background_updates() const; + unique_ptr audios_manager_; unique_ptr callback_queries_manager_; unique_ptr documents_manager_; @@ -306,6 +312,8 @@ class Td final : public Actor { enum : int8 { RequestActorIdType = 1, ActorIdType = 2 }; Container> request_actors_; + bool can_ignore_background_updates_ = false; + bool is_online_ = false; bool is_bot_online_ = false; NetQueryRef update_status_query_; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index d3926506e..8ac77bb4c 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -449,7 +449,7 @@ void UpdatesManager::save_pts(int32 pts) { G()->td_db()->get_binlog_pmc()->erase("updates.pts"); last_pts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY; pending_pts_ = 0; - } else if (!G()->ignore_background_updates()) { + } else if (!td_->ignore_background_updates()) { auto now = Time::now(); auto delay = last_pts_save_time_ + MAX_PTS_SAVE_DELAY - now; if (delay <= 0 || !td_->auth_manager_->is_bot()) { @@ -466,7 +466,7 @@ void UpdatesManager::save_pts(int32 pts) { } void UpdatesManager::save_qts(int32 qts) { - if (!G()->ignore_background_updates()) { + if (!td_->ignore_background_updates()) { auto now = Time::now(); auto delay = last_qts_save_time_ + MAX_PTS_SAVE_DELAY - now; if (delay <= 0 || !td_->auth_manager_->is_bot()) { @@ -543,7 +543,7 @@ void UpdatesManager::set_date(int32 date, bool from_update, string date_source) date_ = date; date_source_ = std::move(date_source); - if (!G()->ignore_background_updates()) { + if (!td_->ignore_background_updates()) { G()->td_db()->get_binlog_pmc()->set("updates.date", to_string(date)); } } else if (date < date_) { @@ -1506,11 +1506,11 @@ void UpdatesManager::init_state() { return; } - bool drop_state = !G()->use_file_database() && !G()->use_secret_chats() && td_->auth_manager_->is_bot() && + bool drop_state = td_->can_ignore_background_updates() && td_->auth_manager_->is_bot() && td_->option_manager_->get_option_integer("since_last_open") >= 2 * 86400; auto pmc = G()->td_db()->get_binlog_pmc(); - if (G()->ignore_background_updates() || drop_state) { + if (td_->ignore_background_updates() || drop_state) { // just in case pmc->erase("updates.pts"); pmc->erase("updates.qts");