Move ignore_background_updates() to Td.

This commit is contained in:
levlam 2023-03-13 21:13:59 +03:00
parent af838647df
commit 367d3eaa2b
6 changed files with 23 additions and 20 deletions

View File

@ -231,10 +231,6 @@ DcId Global::get_webfile_dc_id() const {
return DcId::internal(dc_id); 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<NetQueryStats> net_query_stats) { void Global::set_net_query_stats(std::shared_ptr<NetQueryStats> net_query_stats) {
net_query_creator_.set_create_func( net_query_creator_.set_create_func(
[net_query_stats = std::move(net_query_stats)] { return td::make_unique<NetQueryCreator>(net_query_stats); }); [net_query_stats = std::move(net_query_stats)] { return td::make_unique<NetQueryCreator>(net_query_stats); });

View File

@ -110,8 +110,6 @@ class Global final : public ActorContext {
return parameters_.use_test_dc; return parameters_.use_test_dc;
} }
bool ignore_background_updates() const;
NetQueryCreator &net_query_creator() { NetQueryCreator &net_query_creator() {
return *net_query_creator_.get(); return *net_query_creator_.get();
} }
@ -408,10 +406,6 @@ class Global final : public ActorContext {
return parameters_.use_message_db; return parameters_.use_message_db;
} }
bool use_secret_chats() const {
return parameters_.use_secret_chats;
}
int32 get_gc_scheduler_id() const { int32 get_gc_scheduler_id() const {
return gc_scheduler_id_; return gc_scheduler_id_;
} }

View File

@ -13733,7 +13733,7 @@ void MessagesManager::init() {
main_dialog_list_position_ = 0; 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<DialogFilterId, DialogFilterIdHash> server_dialog_filter_ids; std::unordered_set<DialogFilterId, DialogFilterIdHash> server_dialog_filter_ids;
for (auto &dialog_filter : log_event.server_dialog_filters_out) { for (auto &dialog_filter : log_event.server_dialog_filters_out) {
if (dialog_filter->dialog_filter_id.is_valid() && 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 { 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 G()->td_db()->get_binlog_pmc()->erase(get_channel_pts_key(dialog_id)); // just in case
return 0; 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); 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)); G()->td_db()->get_binlog_pmc()->set(get_channel_pts_key(d->dialog_id), to_string(new_pts));
} }
} else if (new_pts < d->pts) { } else if (new_pts < d->pts) {
@ -39595,7 +39595,7 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool
return; 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(); auto channel_id = dialog_id.get_channel_id();
CHECK(input_channel->get_id() == telegram_api::inputChannel::ID); CHECK(input_channel->get_id() == telegram_api::inputChannel::ID);
auto access_hash = static_cast<const telegram_api::inputChannel &>(*input_channel).access_hash_; auto access_hash = static_cast<const telegram_api::inputChannel &>(*input_channel).access_hash_;
@ -41318,7 +41318,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
break; break;
} }
case LogEvent::HandlerType::GetChannelDifference: { case LogEvent::HandlerType::GetChannelDifference: {
if (G()->ignore_background_updates()) { if (td_->ignore_background_updates()) {
binlog_erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }

View File

@ -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_); 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) { bool Td::is_authentication_request(int32 id) {
switch (id) { switch (id) {
case td_api::setTdlibParameters::ID: case td_api::setTdlibParameters::ID:
@ -2962,6 +2966,7 @@ void Td::run_request(uint64 id, tl_object_ptr<td_api::Function> function) {
VLOG(td_init) << "Begin to open database"; VLOG(td_init) << "Begin to open database";
set_parameters_request_id_ = id; set_parameters_request_id_ = id;
can_ignore_background_updates_ = !r_parameters.ok().use_file_db && !r_parameters.ok().use_secret_chats;
auto promise = auto promise =
PromiseCreator::lambda([actor_id = actor_id(this)](Result<TdDb::OpenedDatabase> r_opened_database) { PromiseCreator::lambda([actor_id = actor_id(this)](Result<TdDb::OpenedDatabase> r_opened_database) {

View File

@ -133,6 +133,12 @@ class Td final : public Actor {
void set_is_bot_online(bool is_bot_online); 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<AudiosManager> audios_manager_; unique_ptr<AudiosManager> audios_manager_;
unique_ptr<CallbackQueriesManager> callback_queries_manager_; unique_ptr<CallbackQueriesManager> callback_queries_manager_;
unique_ptr<DocumentsManager> documents_manager_; unique_ptr<DocumentsManager> documents_manager_;
@ -306,6 +312,8 @@ class Td final : public Actor {
enum : int8 { RequestActorIdType = 1, ActorIdType = 2 }; enum : int8 { RequestActorIdType = 1, ActorIdType = 2 };
Container<ActorOwn<Actor>> request_actors_; Container<ActorOwn<Actor>> request_actors_;
bool can_ignore_background_updates_ = false;
bool is_online_ = false; bool is_online_ = false;
bool is_bot_online_ = false; bool is_bot_online_ = false;
NetQueryRef update_status_query_; NetQueryRef update_status_query_;

View File

@ -449,7 +449,7 @@ void UpdatesManager::save_pts(int32 pts) {
G()->td_db()->get_binlog_pmc()->erase("updates.pts"); G()->td_db()->get_binlog_pmc()->erase("updates.pts");
last_pts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY; last_pts_save_time_ -= 2 * MAX_PTS_SAVE_DELAY;
pending_pts_ = 0; pending_pts_ = 0;
} else if (!G()->ignore_background_updates()) { } else if (!td_->ignore_background_updates()) {
auto now = Time::now(); auto now = Time::now();
auto delay = last_pts_save_time_ + MAX_PTS_SAVE_DELAY - now; auto delay = last_pts_save_time_ + MAX_PTS_SAVE_DELAY - now;
if (delay <= 0 || !td_->auth_manager_->is_bot()) { if (delay <= 0 || !td_->auth_manager_->is_bot()) {
@ -466,7 +466,7 @@ void UpdatesManager::save_pts(int32 pts) {
} }
void UpdatesManager::save_qts(int32 qts) { void UpdatesManager::save_qts(int32 qts) {
if (!G()->ignore_background_updates()) { if (!td_->ignore_background_updates()) {
auto now = Time::now(); auto now = Time::now();
auto delay = last_qts_save_time_ + MAX_PTS_SAVE_DELAY - now; auto delay = last_qts_save_time_ + MAX_PTS_SAVE_DELAY - now;
if (delay <= 0 || !td_->auth_manager_->is_bot()) { 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_ = date;
date_source_ = std::move(date_source); 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)); G()->td_db()->get_binlog_pmc()->set("updates.date", to_string(date));
} }
} else if (date < date_) { } else if (date < date_) {
@ -1506,11 +1506,11 @@ void UpdatesManager::init_state() {
return; 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; td_->option_manager_->get_option_integer("since_last_open") >= 2 * 86400;
auto pmc = G()->td_db()->get_binlog_pmc(); 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 // just in case
pmc->erase("updates.pts"); pmc->erase("updates.pts");
pmc->erase("updates.qts"); pmc->erase("updates.qts");