From 2633de8b53d7ec57b1e4fdd3033024342b510271 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 20 Jul 2022 14:48:12 +0300 Subject: [PATCH] Update TDLib and destroy some big data storages asynchronously. --- telegram-bot-api/Client.cpp | 17 +++++++++++++++-- telegram-bot-api/Client.h | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 70e7c78..f045df5 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -185,6 +185,12 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te CHECK(is_inited); } +Client::~Client() { + td::Scheduler::instance()->destroy_on_scheduler(get_file_gc_scheduler_id(), messages_, users_, groups_, supergroups_, + chats_, reply_message_ids_, yet_unsent_reply_message_ids_, + sticker_set_names_); +} + bool Client::init_methods() { methods_.emplace("getme", &Client::process_get_me_query); methods_.emplace("getmycommands", &Client::process_get_my_commands_query); @@ -4856,7 +4862,7 @@ void Client::on_closed() { if (logging_out_) { parameters_->shared_data_->webhook_db_->erase(bot_token_with_dc_); - td::Scheduler::instance()->run_on_scheduler(get_database_scheduler_id(), + td::Scheduler::instance()->run_on_scheduler(get_file_gc_scheduler_id(), [actor_id = actor_id(this), dir = dir_](td::Unit) { CHECK(dir.size() >= 24); CHECK(dir.back() == TD_DIR_SLASH); @@ -4883,12 +4889,19 @@ void Client::timeout_expired() { } td::int32 Client::get_database_scheduler_id() { - // NB: the same scheduler as for database in Td + // the same scheduler as for database in Td auto current_scheduler_id = td::Scheduler::instance()->sched_id(); auto scheduler_count = td::Scheduler::instance()->sched_count(); return td::min(current_scheduler_id + 1, scheduler_count - 1); } +td::int32 Client::get_file_gc_scheduler_id() { + // the same scheduler as for file GC in Td + auto current_scheduler_id = td::Scheduler::instance()->sched_id(); + auto scheduler_count = td::Scheduler::instance()->sched_count(); + return td::min(current_scheduler_id + 2, scheduler_count - 1); +} + void Client::clear_tqueue() { CHECK(webhook_id_.empty()); auto &tqueue = parameters_->shared_data_->tqueue_; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index af10157..f7d8573 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -42,6 +42,11 @@ class Client final : public WebhookActor::Callback { public: Client(td::ActorShared<> parent, const td::string &bot_token, bool is_test_dc, td::int64 tqueue_id, std::shared_ptr parameters, td::ActorId stat_actor); + Client(const Client &) = delete; + Client &operator=(const Client &) = delete; + Client(Client &&) = delete; + Client &operator=(Client &&) = delete; + ~Client(); void send(PromisedQueryPtr query) final; @@ -304,6 +309,8 @@ class Client final : public WebhookActor::Callback { static int32 get_database_scheduler_id(); + static int32 get_file_gc_scheduler_id(); + void clear_tqueue(); bool allow_update_before_authorization(const td_api::Object *update) const;