Merge GetChat queries.

This commit is contained in:
levlam 2023-01-13 14:45:53 +03:00
parent 13e8094aaa
commit d3690e1502
2 changed files with 6 additions and 3 deletions

View File

@ -3924,6 +3924,9 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent
}); });
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users)); td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
}); });
get_chat_queries_.set_merge_function([this](vector<int64> query_ids, Promise<Unit> &&promise) {
td_->create_handler<GetChatsQuery>(std::move(promise))->send(std::move(query_ids));
});
} }
ContactsManager::~ContactsManager() { ContactsManager::~ContactsManager() {
@ -16114,7 +16117,7 @@ bool ContactsManager::get_chat(ChatId chat_id, int left_tries, Promise<Unit> &&p
} }
if (left_tries > 1) { if (left_tries > 1) {
td_->create_handler<GetChatsQuery>(std::move(promise))->send(vector<int64>{chat_id.get()}); get_chat_queries_.add_query(chat_id.get(), std::move(promise));
return false; return false;
} }
@ -16131,8 +16134,7 @@ void ContactsManager::reload_chat(ChatId chat_id, Promise<Unit> &&promise) {
return promise.set_error(Status::Error(400, "Invalid basic group identifier")); return promise.set_error(Status::Error(400, "Invalid basic group identifier"));
} }
// there is no much reason to combine different requests into one request get_chat_queries_.add_query(chat_id.get(), std::move(promise));
td_->create_handler<GetChatsQuery>(std::move(promise))->send(vector<int64>{chat_id.get()});
} }
const ContactsManager::ChatFull *ContactsManager::get_chat_full(ChatId chat_id) const { const ContactsManager::ChatFull *ContactsManager::get_chat_full(ChatId chat_id) const {

View File

@ -1878,6 +1878,7 @@ class ContactsManager final : public Actor {
FlatHashSet<SecretChatId, SecretChatIdHash> loaded_from_database_secret_chats_; FlatHashSet<SecretChatId, SecretChatIdHash> loaded_from_database_secret_chats_;
QueryMerger get_user_queries_{"GetUserMerger", 3, 50}; QueryMerger get_user_queries_{"GetUserMerger", 3, 50};
QueryMerger get_chat_queries_{"GetChatMerger", 3, 50};
QueryCombiner get_user_full_queries_{"GetUserFullCombiner", 2.0}; QueryCombiner get_user_full_queries_{"GetUserFullCombiner", 2.0};
QueryCombiner get_chat_full_queries_{"GetChatFullCombiner", 2.0}; QueryCombiner get_chat_full_queries_{"GetChatFullCombiner", 2.0};