From 38fe0cc6fcfaa4ef530e285ccbbfa4cd9e72269d Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 17 Feb 2022 16:09:17 +0300 Subject: [PATCH] Preload users from database before adding them from binlog. --- td/telegram/ContactsManager.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f0b6d421a..f309965ab 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8517,12 +8517,26 @@ void ContactsManager::on_binlog_user_event(BinlogEvent &&event) { log_event_parse(log_event, event.data_).ensure(); auto user_id = log_event.user_id; - if (have_user(user_id)) { + if (have_min_user(user_id)) { LOG(ERROR) << "Skip adding already added " << user_id; binlog_erase(G()->td_db()->get_binlog(), event.id_); return; } + if (!log_event.u.is_received) { + // we must preload received inaccessible users from database in order to not save + // the min-user to the database and to not override access_hash and another info + if (!have_user_force(user_id)) { + LOG(INFO) << "Receive inaccessible " << user_id << " from binlog"; + } + } else if (log_event.u.is_contact && !are_contacts_loaded_) { + // preload contact users from database to know that is_contact didn't changed + // and the list of contacts doesn't need to be saved to the database + if (!have_user_force(user_id)) { + LOG(INFO) << "Receive contact " << user_id << " for the first time from binlog"; + } + } + LOG(INFO) << "Add " << user_id << " from binlog"; User *u = add_user(user_id, "on_binlog_user_event"); *u = std::move(log_event.u); // users come from binlog before all other events, so just add them