Don't ignore forcely loaded after close users and chats.

This commit is contained in:
levlam 2021-07-19 04:27:44 +03:00
parent 13fcffd711
commit 58c99ed63a
2 changed files with 24 additions and 20 deletions

View File

@ -8411,13 +8411,14 @@ void ContactsManager::load_user_from_database_impl(UserId user_id, Promise<Unit>
G()->td_db()->get_sqlite_pmc()->get(get_user_database_key(user_id), PromiseCreator::lambda([user_id](string value) { G()->td_db()->get_sqlite_pmc()->get(get_user_database_key(user_id), PromiseCreator::lambda([user_id](string value) {
send_closure(G()->contacts_manager(), send_closure(G()->contacts_manager(),
&ContactsManager::on_load_user_from_database, user_id, &ContactsManager::on_load_user_from_database, user_id,
std::move(value)); std::move(value), false);
})); }));
} }
} }
void ContactsManager::on_load_user_from_database(UserId user_id, string value) { void ContactsManager::on_load_user_from_database(UserId user_id, string value, bool force) {
if (G()->close_flag()) { if (G()->close_flag() && !force) {
// the user is in Binlog and will be saved after restart
return; return;
} }
@ -8549,7 +8550,7 @@ ContactsManager::User *ContactsManager::get_user_force_impl(UserId user_id) {
} }
LOG(INFO) << "Trying to load " << user_id << " from database"; LOG(INFO) << "Trying to load " << user_id << " from database";
on_load_user_from_database(user_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_user_database_key(user_id))); on_load_user_from_database(user_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_user_database_key(user_id)), true);
return get_user(user_id); return get_user(user_id);
} }
@ -8704,13 +8705,14 @@ void ContactsManager::load_chat_from_database_impl(ChatId chat_id, Promise<Unit>
G()->td_db()->get_sqlite_pmc()->get(get_chat_database_key(chat_id), PromiseCreator::lambda([chat_id](string value) { G()->td_db()->get_sqlite_pmc()->get(get_chat_database_key(chat_id), PromiseCreator::lambda([chat_id](string value) {
send_closure(G()->contacts_manager(), send_closure(G()->contacts_manager(),
&ContactsManager::on_load_chat_from_database, chat_id, &ContactsManager::on_load_chat_from_database, chat_id,
std::move(value)); std::move(value), false);
})); }));
} }
} }
void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value) { void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value, bool force) {
if (G()->close_flag()) { if (G()->close_flag() && !force) {
// the chat is in Binlog and will be saved after restart
return; return;
} }
@ -8786,7 +8788,7 @@ ContactsManager::Chat *ContactsManager::get_chat_force(ChatId chat_id) {
} }
LOG(INFO) << "Trying to load " << chat_id << " from database"; LOG(INFO) << "Trying to load " << chat_id << " from database";
on_load_chat_from_database(chat_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_chat_database_key(chat_id))); on_load_chat_from_database(chat_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_chat_database_key(chat_id)), true);
return get_chat(chat_id); return get_chat(chat_id);
} }
@ -8942,13 +8944,14 @@ void ContactsManager::load_channel_from_database_impl(ChannelId channel_id, Prom
G()->td_db()->get_sqlite_pmc()->get( G()->td_db()->get_sqlite_pmc()->get(
get_channel_database_key(channel_id), PromiseCreator::lambda([channel_id](string value) { get_channel_database_key(channel_id), PromiseCreator::lambda([channel_id](string value) {
send_closure(G()->contacts_manager(), &ContactsManager::on_load_channel_from_database, channel_id, send_closure(G()->contacts_manager(), &ContactsManager::on_load_channel_from_database, channel_id,
std::move(value)); std::move(value), false);
})); }));
} }
} }
void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string value) { void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string value, bool force) {
if (G()->close_flag()) { if (G()->close_flag() && !force) {
// the channel is in Binlog and will be saved after restart
return; return;
} }
@ -9039,7 +9042,7 @@ ContactsManager::Channel *ContactsManager::get_channel_force(ChannelId channel_i
LOG(INFO) << "Trying to load " << channel_id << " from database"; LOG(INFO) << "Trying to load " << channel_id << " from database";
on_load_channel_from_database(channel_id, on_load_channel_from_database(channel_id,
G()->td_db()->get_sqlite_sync_pmc()->get(get_channel_database_key(channel_id))); G()->td_db()->get_sqlite_sync_pmc()->get(get_channel_database_key(channel_id)), true);
return get_channel(channel_id); return get_channel(channel_id);
} }
@ -9197,13 +9200,14 @@ void ContactsManager::load_secret_chat_from_database_impl(SecretChatId secret_ch
G()->td_db()->get_sqlite_pmc()->get( G()->td_db()->get_sqlite_pmc()->get(
get_secret_chat_database_key(secret_chat_id), PromiseCreator::lambda([secret_chat_id](string value) { get_secret_chat_database_key(secret_chat_id), PromiseCreator::lambda([secret_chat_id](string value) {
send_closure(G()->contacts_manager(), &ContactsManager::on_load_secret_chat_from_database, secret_chat_id, send_closure(G()->contacts_manager(), &ContactsManager::on_load_secret_chat_from_database, secret_chat_id,
std::move(value)); std::move(value), false);
})); }));
} }
} }
void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value) { void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value, bool force) {
if (G()->close_flag()) { if (G()->close_flag() && !force) {
// the secret chat is in Binlog and will be saved after restart
return; return;
} }
@ -9280,7 +9284,7 @@ ContactsManager::SecretChat *ContactsManager::get_secret_chat_force(SecretChatId
LOG(INFO) << "Trying to load " << secret_chat_id << " from database"; LOG(INFO) << "Trying to load " << secret_chat_id << " from database";
on_load_secret_chat_from_database( on_load_secret_chat_from_database(
secret_chat_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_secret_chat_database_key(secret_chat_id))); secret_chat_id, G()->td_db()->get_sqlite_sync_pmc()->get(get_secret_chat_database_key(secret_chat_id)), true);
return get_secret_chat(secret_chat_id); return get_secret_chat(secret_chat_id);
} }

View File

@ -1268,7 +1268,7 @@ class ContactsManager final : public Actor {
void on_save_user_to_database(UserId user_id, bool success); void on_save_user_to_database(UserId user_id, bool success);
void load_user_from_database(User *u, UserId user_id, Promise<Unit> promise); void load_user_from_database(User *u, UserId user_id, Promise<Unit> promise);
void load_user_from_database_impl(UserId user_id, Promise<Unit> promise); void load_user_from_database_impl(UserId user_id, Promise<Unit> promise);
void on_load_user_from_database(UserId user_id, string value); void on_load_user_from_database(UserId user_id, string value, bool force);
void save_chat(Chat *c, ChatId chat_id, bool from_binlog); void save_chat(Chat *c, ChatId chat_id, bool from_binlog);
static string get_chat_database_key(ChatId chat_id); static string get_chat_database_key(ChatId chat_id);
@ -1278,7 +1278,7 @@ class ContactsManager final : public Actor {
void on_save_chat_to_database(ChatId chat_id, bool success); void on_save_chat_to_database(ChatId chat_id, bool success);
void load_chat_from_database(Chat *c, ChatId chat_id, Promise<Unit> promise); void load_chat_from_database(Chat *c, ChatId chat_id, Promise<Unit> promise);
void load_chat_from_database_impl(ChatId chat_id, Promise<Unit> promise); void load_chat_from_database_impl(ChatId chat_id, Promise<Unit> promise);
void on_load_chat_from_database(ChatId chat_id, string value); void on_load_chat_from_database(ChatId chat_id, string value, bool force);
void save_channel(Channel *c, ChannelId channel_id, bool from_binlog); void save_channel(Channel *c, ChannelId channel_id, bool from_binlog);
static string get_channel_database_key(ChannelId channel_id); static string get_channel_database_key(ChannelId channel_id);
@ -1288,7 +1288,7 @@ class ContactsManager final : public Actor {
void on_save_channel_to_database(ChannelId channel_id, bool success); void on_save_channel_to_database(ChannelId channel_id, bool success);
void load_channel_from_database(Channel *c, ChannelId channel_id, Promise<Unit> promise); void load_channel_from_database(Channel *c, ChannelId channel_id, Promise<Unit> promise);
void load_channel_from_database_impl(ChannelId channel_id, Promise<Unit> promise); void load_channel_from_database_impl(ChannelId channel_id, Promise<Unit> promise);
void on_load_channel_from_database(ChannelId channel_id, string value); void on_load_channel_from_database(ChannelId channel_id, string value, bool force);
void save_secret_chat(SecretChat *c, SecretChatId secret_chat_id, bool from_binlog); void save_secret_chat(SecretChat *c, SecretChatId secret_chat_id, bool from_binlog);
static string get_secret_chat_database_key(SecretChatId secret_chat_id); static string get_secret_chat_database_key(SecretChatId secret_chat_id);
@ -1298,7 +1298,7 @@ class ContactsManager final : public Actor {
void on_save_secret_chat_to_database(SecretChatId secret_chat_id, bool success); void on_save_secret_chat_to_database(SecretChatId secret_chat_id, bool success);
void load_secret_chat_from_database(SecretChat *c, SecretChatId secret_chat_id, Promise<Unit> promise); void load_secret_chat_from_database(SecretChat *c, SecretChatId secret_chat_id, Promise<Unit> promise);
void load_secret_chat_from_database_impl(SecretChatId secret_chat_id, Promise<Unit> promise); void load_secret_chat_from_database_impl(SecretChatId secret_chat_id, Promise<Unit> promise);
void on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value); void on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value, bool force);
void save_user_full(const UserFull *user_full, UserId user_id); void save_user_full(const UserFull *user_full, UserId user_id);
static string get_user_full_database_key(UserId user_id); static string get_user_full_database_key(UserId user_id);