From b29a945b1aa45d4402f085e54a8b614e1b2641e5 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 16 May 2020 02:25:03 +0300 Subject: [PATCH] Ignore SQLite key-value responses after close. GitOrigin-RevId: a91a2dbbf8efcda91959aabfcaca964caa6fe3c3 --- td/telegram/AnimationsManager.cpp | 3 +++ td/telegram/BackgroundManager.cpp | 4 +++ td/telegram/ContactsManager.cpp | 44 ++++++++++++++++++++++++++++++- td/telegram/HashtagHints.cpp | 4 +++ td/telegram/MessagesManager.cpp | 3 +++ td/telegram/StickersManager.cpp | 18 +++++++++++++ td/telegram/WebPagesManager.cpp | 12 +++++++++ 7 files changed, 87 insertions(+), 1 deletion(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index e0a91aa4..59e62d88 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -501,6 +501,9 @@ void AnimationsManager::load_saved_animations(Promise &&promise) { } void AnimationsManager::on_load_saved_animations_from_database(const string &value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Saved animations aren't found in database"; reload_saved_animations(true); diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 69300f8e..ffbb8c93 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -473,6 +473,10 @@ BackgroundId BackgroundManager::search_background(const string &name, Promiseclose_flag()) { + return; + } + auto promises_it = being_loaded_from_database_backgrounds_.find(name); CHECK(promises_it != being_loaded_from_database_backgrounds_.end()); auto promises = std::move(promises_it->second); diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 46f649a7..c1ad3aa7 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4718,6 +4718,10 @@ void ContactsManager::load_imported_contacts(Promise &&promise) { } void ContactsManager::on_load_imported_contacts_from_database(string value) { + if (G()->close_flag()) { + return; + } + CHECK(!are_imported_contacts_loaded_); if (need_clear_imported_contacts_) { need_clear_imported_contacts_ = false; @@ -6673,6 +6677,9 @@ void ContactsManager::on_deleted_contacts(const vector &deleted_contact_ } void ContactsManager::save_next_contacts_sync_date() { + if (G()->close_flag()) { + return; + } if (!G()->parameters().use_chat_info_db) { return; } @@ -6769,6 +6776,9 @@ void ContactsManager::on_get_contacts_failed(Status error) { } void ContactsManager::on_load_contacts_from_database(string value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { reload_contacts(true); return; @@ -7161,6 +7171,10 @@ void ContactsManager::save_user_to_database_impl(User *u, UserId user_id, string } void ContactsManager::on_save_user_to_database(UserId user_id, bool success) { + if (G()->close_flag()) { + return; + } + User *u = get_user(user_id); CHECK(u != nullptr); LOG_CHECK(u->is_being_saved) << user_id << " " << u->is_saved << " " << u->is_status_saved << " " @@ -7213,6 +7227,10 @@ void ContactsManager::load_user_from_database_impl(UserId user_id, Promise } void ContactsManager::on_load_user_from_database(UserId user_id, string value) { + if (G()->close_flag()) { + return; + } + if (!loaded_from_database_users_.insert(user_id).second) { return; } @@ -7427,6 +7445,10 @@ void ContactsManager::save_chat_to_database_impl(Chat *c, ChatId chat_id, string } void ContactsManager::on_save_chat_to_database(ChatId chat_id, bool success) { + if (G()->close_flag()) { + return; + } + Chat *c = get_chat(chat_id); CHECK(c != nullptr); CHECK(c->is_being_saved); @@ -7473,6 +7495,10 @@ void ContactsManager::load_chat_from_database_impl(ChatId chat_id, Promise } void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value) { + if (G()->close_flag()) { + return; + } + if (!loaded_from_database_chats_.insert(chat_id).second) { return; } @@ -7656,6 +7682,10 @@ void ContactsManager::save_channel_to_database_impl(Channel *c, ChannelId channe } void ContactsManager::on_save_channel_to_database(ChannelId channel_id, bool success) { + if (G()->close_flag()) { + return; + } + Channel *c = get_channel(channel_id); CHECK(c != nullptr); CHECK(c->is_being_saved); @@ -7702,6 +7732,10 @@ void ContactsManager::load_channel_from_database_impl(ChannelId channel_id, Prom } void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string value) { + if (G()->close_flag()) { + return; + } + if (!loaded_from_database_channels_.insert(channel_id).second) { return; } @@ -7888,6 +7922,10 @@ void ContactsManager::save_secret_chat_to_database_impl(SecretChat *c, SecretCha } void ContactsManager::on_save_secret_chat_to_database(SecretChatId secret_chat_id, bool success) { + if (G()->close_flag()) { + return; + } + SecretChat *c = get_secret_chat(secret_chat_id); CHECK(c != nullptr); CHECK(c->is_being_saved); @@ -7935,6 +7973,10 @@ void ContactsManager::load_secret_chat_from_database_impl(SecretChatId secret_ch } void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value) { + if (G()->close_flag()) { + return; + } + if (!loaded_from_database_secret_chats_.insert(secret_chat_id).second) { return; } @@ -12728,7 +12770,7 @@ void ContactsManager::load_dialog_administrators(DialogId dialog_id, Promise &&promise) { - if (value.empty()) { + if (value.empty() || G()->close_flag()) { promise.set_value(Unit()); return; } diff --git a/td/telegram/HashtagHints.cpp b/td/telegram/HashtagHints.cpp index d587c682..06d6c8f5 100644 --- a/td/telegram/HashtagHints.cpp +++ b/td/telegram/HashtagHints.cpp @@ -86,6 +86,10 @@ void HashtagHints::hashtag_used_impl(const string &hashtag) { } void HashtagHints::from_db(Result data, bool dummy) { + if (G()->close_flag()) { + return; + } + sync_with_db_ = true; if (data.is_error() || data.ok().empty()) { return; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 84fd51ee..5c3084e0 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -16588,6 +16588,9 @@ vector MessagesManager::get_active_live_location_messages(Promise } void MessagesManager::on_load_active_live_location_full_message_ids_from_database(string value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Active live location messages aren't found in the database"; on_load_active_live_location_messages_finished(); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 593af40d..76c87948 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3060,6 +3060,9 @@ void StickersManager::load_installed_sticker_sets(bool is_masks, Promise & } void StickersManager::on_load_installed_sticker_sets_from_database(bool is_masks, string value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Installed " << (is_masks ? "mask " : "") << "sticker sets aren't found in database"; reload_installed_sticker_sets(is_masks, true); @@ -3266,6 +3269,9 @@ void StickersManager::load_sticker_sets_without_stickers(vector && } void StickersManager::on_load_sticker_set_from_database(StickerSetId sticker_set_id, bool with_stickers, string value) { + if (G()->close_flag()) { + return; + } StickerSet *sticker_set = get_sticker_set(sticker_set_id); CHECK(sticker_set != nullptr); if (sticker_set->was_loaded) { @@ -3852,6 +3858,9 @@ void StickersManager::load_featured_sticker_sets(Promise &&promise) { } void StickersManager::on_load_featured_sticker_sets_from_database(string value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Trending sticker sets aren't found in database"; reload_featured_sticker_sets(true); @@ -3928,6 +3937,9 @@ void StickersManager::load_old_featured_sticker_sets(Promise &&promise) { } void StickersManager::on_load_old_featured_sticker_sets_from_database(uint32 generation, string value) { + if (G()->close_flag()) { + return; + } if (generation != old_featured_sticker_set_generation_) { return; } @@ -4914,6 +4926,9 @@ void StickersManager::load_recent_stickers(bool is_attached, Promise &&pro } void StickersManager::on_load_recent_stickers_from_database(bool is_attached, string value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Recent " << (is_attached ? "attached " : "") << "stickers aren't found in database"; reload_recent_stickers(is_attached, true); @@ -5332,6 +5347,9 @@ void StickersManager::load_favorite_stickers(Promise &&promise) { } void StickersManager::on_load_favorite_stickers_from_database(const string &value) { + if (G()->close_flag()) { + return; + } if (value.empty()) { LOG(INFO) << "Favorite stickers aren't found in database"; reload_favorite_stickers(true); diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 55d5ecd9..06bddaf1 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -919,6 +919,9 @@ void WebPagesManager::reload_web_page_instant_view(WebPageId web_page_id) { } void WebPagesManager::on_load_web_page_instant_view_from_database(WebPageId web_page_id, string value) { + if (G()->close_flag()) { + return; + } CHECK(G()->parameters().use_message_db); LOG(INFO) << "Successfully loaded " << web_page_id << " instant view of size " << value.size() << " from database"; // G()->td_db()->get_sqlite_pmc()->erase(get_web_page_instant_view_database_key(web_page_id), Auto()); @@ -1072,6 +1075,9 @@ void WebPagesManager::load_web_page_by_url(const string &url, Promise &&pr void WebPagesManager::on_load_web_page_id_by_url_from_database(const string &url, string value, Promise &&promise) { + if (G()->close_flag()) { + return; + } LOG(INFO) << "Successfully loaded url \"" << url << "\" of size " << value.size() << " from database"; // G()->td_db()->get_sqlite_pmc()->erase(get_web_page_url_database_key(web_page_id), Auto()); // return; @@ -1545,6 +1551,9 @@ string WebPagesManager::get_web_page_database_key(WebPageId web_page_id) { } void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool success) { + if (G()->close_flag()) { + return; + } const WebPage *web_page = get_web_page(web_page_id); if (web_page == nullptr) { LOG(ERROR) << "Can't find " << (success ? "saved " : "failed to save ") << web_page_id; @@ -1583,6 +1592,9 @@ void WebPagesManager::load_web_page_from_database(WebPageId web_page_id, Promise } void WebPagesManager::on_load_web_page_from_database(WebPageId web_page_id, string value) { + if (G()->close_flag()) { + return; + } if (!loaded_from_database_web_pages_.insert(web_page_id).second) { return; }