From 260eee8bff62ddf05b62455188039b801bb153c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 10 May 2021 01:59:35 +0300 Subject: [PATCH] Avoid upgrade of read transaction to a write transaction. --- td/telegram/MessagesManager.cpp | 14 ++++++++------ td/telegram/StickersManager.cpp | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5c3cdb9ba..750f33ba9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27108,8 +27108,9 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat d = get_dialog(it->second); CHECK(d != nullptr); } else if (G()->parameters().use_message_db) { - G()->td_db()->get_dialog_db_sync()->begin_transaction().ensure(); - auto r_value = G()->td_db()->get_dialog_db_sync()->get_notification_group(group_id); + auto *dialog_db = G()->td_db()->get_dialog_db_sync(); + dialog_db->begin_transaction().ensure(); // read transaction + auto r_value = dialog_db->get_notification_group(group_id); if (r_value.is_ok()) { VLOG(notifications) << "Loaded " << r_value.ok() << " from database by " << group_id; d = get_dialog_force(r_value.ok().dialog_id, "get_message_notification_group_force"); @@ -27117,7 +27118,7 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat CHECK(r_value.error().message() == "Not found"); VLOG(notifications) << "Failed to load " << group_id << " from database"; } - G()->td_db()->get_dialog_db_sync()->commit_transaction().ensure(); + dialog_db->commit_transaction().ensure(); } if (d == nullptr) { @@ -27403,9 +27404,10 @@ vector MessagesManager::get_message_notification_group_key VLOG(notifications) << "Trying to load " << limit << " message notification groups from database from " << from_group_key; - G()->td_db()->get_dialog_db_sync()->begin_transaction().ensure(); + auto *dialog_db = G()->td_db()->get_dialog_db_sync(); + dialog_db->begin_transaction().ensure(); // read transaction Result> r_notification_group_keys = - G()->td_db()->get_dialog_db_sync()->get_notification_groups_by_last_notification_date(from_group_key, limit); + dialog_db->get_notification_groups_by_last_notification_date(from_group_key, limit); r_notification_group_keys.ensure(); auto group_keys = r_notification_group_keys.move_as_ok(); @@ -27424,7 +27426,7 @@ vector MessagesManager::get_message_notification_group_key VLOG(notifications) << "Loaded " << group_key << " from database"; result.push_back(group_key); } - G()->td_db()->get_dialog_db_sync()->commit_transaction().ensure(); + dialog_db->commit_transaction().ensure(); return result; } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 05151d843..122323af3 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6415,6 +6415,9 @@ void StickersManager::on_get_emoji_keywords_difference( version = keywords->version_; auto *pmc = G()->td_db()->get_sqlite_sync_pmc(); pmc->begin_transaction().ensure(); + // set must be the first operation to start a write transaction + pmc->set(get_emoji_language_code_version_database_key(language_code), to_string(version)); + pmc->set(get_emoji_language_code_last_difference_time_database_key(language_code), to_string(G()->unix_time())); for (auto &keyword_ptr : keywords->keywords_) { switch (keyword_ptr->get_id()) { case telegram_api::emojiKeyword::ID: { @@ -6467,8 +6470,6 @@ void StickersManager::on_get_emoji_keywords_difference( UNREACHABLE(); } } - pmc->set(get_emoji_language_code_version_database_key(language_code), to_string(version)); - pmc->set(get_emoji_language_code_last_difference_time_database_key(language_code), to_string(G()->unix_time())); pmc->commit_transaction().ensure(); emoji_language_code_versions_[language_code] = version; emoji_language_code_last_difference_times_[language_code] = static_cast(Time::now_cached());