From f62632fcbc9d2ac753fd355bafefd812867fe2ee Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 26 Jun 2022 17:11:27 +0300 Subject: [PATCH] Remove rarely used PromiseCreator::lambda with 2 lambdas. --- td/telegram/AuthManager.cpp | 22 ++++++++++------ td/telegram/DialogDb.cpp | 4 +-- td/telegram/MessagesDb.cpp | 5 ++-- td/telegram/MessagesManager.cpp | 44 ++++++++++++++++---------------- td/telegram/SecretChatActor.cpp | 8 +++--- tdactor/td/actor/PromiseFuture.h | 6 ----- 6 files changed, 46 insertions(+), 43 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index fb34fb4dd..861afc1ec 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -77,8 +77,11 @@ void AuthManager::start_up() { if (state_ == State::LoggingOut) { send_log_out_query(); } else if (state_ == State::DestroyingKeys) { - G()->net_query_dispatcher().destroy_auth_keys( - PromiseCreator::lambda([](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore())); + G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result result) { + if (result.is_ok()) { + send_closure_later(G()->td(), &Td::destroy); + } + })); } } void AuthManager::tear_down() { @@ -706,12 +709,15 @@ void AuthManager::destroy_auth_keys() { return; } update_state(State::DestroyingKeys); - auto promise = PromiseCreator::lambda( - [](Unit) { - G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda( - [](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore())); - }, - PromiseCreator::Ignore()); + auto promise = PromiseCreator::lambda([](Result result) { + if (result.is_ok()) { + G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result result) { + if (result.is_ok()) { + send_closure_later(G()->td(), &Td::destroy); + } + })); + } + }); G()->td_db()->get_binlog_pmc()->set("auth", "destroy"); G()->td_db()->get_binlog_pmc()->force_sync(std::move(promise)); } diff --git a/td/telegram/DialogDb.cpp b/td/telegram/DialogDb.cpp index e63475c65..e55c5b378 100644 --- a/td/telegram/DialogDb.cpp +++ b/td/telegram/DialogDb.cpp @@ -443,12 +443,12 @@ class DialogDbAsync final : public DialogDbAsyncInterface { //NB: order is important, destructor of pending_writes_ will change pending_write_results_ std::vector, Status>> pending_write_results_; - vector> pending_writes_; + vector> pending_writes_; // TODO use Action double wakeup_at_ = 0; template void add_write_query(F &&f) { - pending_writes_.push_back(PromiseCreator::lambda(std::forward(f), PromiseCreator::Ignore())); + pending_writes_.push_back(PromiseCreator::lambda(std::forward(f))); if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) { do_flush(); wakeup_at_ = 0; diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 9660492ff..187a1e7ba 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -1216,11 +1216,12 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface { //NB: order is important, destructor of pending_writes_ will change pending_write_results_ vector, Status>> pending_write_results_; - vector> pending_writes_; + vector> pending_writes_; // TODO use Action double wakeup_at_ = 0; + template void add_write_query(F &&f) { - pending_writes_.push_back(PromiseCreator::lambda(std::forward(f), PromiseCreator::Ignore())); + pending_writes_.push_back(PromiseCreator::lambda(std::forward(f))); if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) { do_flush(); wakeup_at_ = 0; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 2caca46c7..4a691047b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3212,11 +3212,11 @@ class SendMessageQuery final : public Td::ResultHandler { {{dialog_id, MessageContentType::Text}, {dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}}); if (G()->shared_config().get_option_boolean("use_quick_ack")) { - query->quick_ack_promise_ = PromiseCreator::lambda( - [random_id](Unit) { - send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); - }, - PromiseCreator::Ignore()); + query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result result) { + if (result.is_ok()) { + send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); + } + }); } *send_query_ref = query.get_weak(); send_query(std::move(query)); @@ -3283,11 +3283,11 @@ class StartBotQuery final : public Td::ResultHandler { telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter), {{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}}); if (G()->shared_config().get_option_boolean("use_quick_ack")) { - query->quick_ack_promise_ = PromiseCreator::lambda( - [random_id](Unit) { - send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); - }, - PromiseCreator::Ignore()); + query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result result) { + if (result.is_ok()) { + send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); + } + }); } auto send_query_ref = query.get_weak(); send_query(std::move(query)); @@ -3525,11 +3525,11 @@ class SendMediaQuery final : public Td::ResultHandler { std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)), {{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}}); if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) { - query->quick_ack_promise_ = PromiseCreator::lambda( - [random_id](Unit) { - send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); - }, - PromiseCreator::Ignore()); + query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result result) { + if (result.is_ok()) { + send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); + } + }); } *send_query_ref = query.get_weak(); send_query(std::move(query)); @@ -3889,13 +3889,13 @@ class ForwardMessagesQuery final : public Td::ResultHandler { std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)), {{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}}); if (G()->shared_config().get_option_boolean("use_quick_ack")) { - query->quick_ack_promise_ = PromiseCreator::lambda( - [random_ids = random_ids_](Unit) { - for (auto random_id : random_ids) { - send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); - } - }, - PromiseCreator::Ignore()); + query->quick_ack_promise_ = PromiseCreator::lambda([random_ids = random_ids_](Result result) { + if (result.is_ok()) { + for (auto random_id : random_ids) { + send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); + } + } + }); } send_query(std::move(query)); } diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index f5e65d9f3..21d145453 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -1436,9 +1436,11 @@ NetQueryPtr SecretChatActor::create_net_query(const log_event::OutboundSecretMes } if (message.is_external && context_->get_config_option_boolean("use_quick_ack")) { query->quick_ack_promise_ = - PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id]( - Unit) { send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id); }, - PromiseCreator::Ignore()); + PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id](Result result) { + if (result.is_ok()) { + send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id); + } + }); } return query; diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index 3e8b355cd..e03738cc2 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -692,12 +692,6 @@ class PromiseCreator { return Promise(td::make_unique>>(std::forward(ok))); } - template > - static Promise lambda(OkT &&ok, FailT &&fail) { - return Promise(td::make_unique, std::decay_t>>( - std::forward(ok), std::forward(fail), false)); - } - template >> static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) { return Promise(td::make_unique>>>(