From 9c961b2eb87cd1f5275de7716ff637705afe480a Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Jan 2021 23:37:00 +0300 Subject: [PATCH] Optimize database_message_id updating in on_get_history. --- td/telegram/MessagesManager.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index f64f20861..170accb66 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8903,7 +8903,6 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ } if (need_update_database_message_ids) { - bool is_dialog_updated = false; if (!d->last_database_message_id.is_valid()) { CHECK(d->last_message_id.is_valid()); MessagesConstIterator it(d, d->last_message_id); @@ -8918,7 +8917,6 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ } --it; } - is_dialog_updated = true; } else { LOG_CHECK(d->last_new_message_id.is_valid()) << dialog_id << " " << from_the_end << " " << d->first_database_message_id << " " @@ -8933,28 +8931,34 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ { MessagesConstIterator it(d, d->first_database_message_id); if (*it != nullptr && ((*it)->message_id == d->first_database_message_id || (*it)->have_next)) { + MessageId new_first_database_message_id = d->first_database_message_id; while (*it != nullptr) { auto message_id = (*it)->message_id; - if ((message_id.is_server() || message_id.is_local()) && message_id < d->first_database_message_id) { - set_dialog_first_database_message_id(d, message_id, "on_get_history 2"); + if ((message_id.is_server() || message_id.is_local()) && message_id < new_first_database_message_id) { + new_first_database_message_id = message_id; try_restore_dialog_reply_markup(d, *it); - is_dialog_updated = true; } --it; } + if (new_first_database_message_id != d->first_database_message_id) { + set_dialog_first_database_message_id(d, new_first_database_message_id, "on_get_history 2"); + } } } { MessagesConstIterator it(d, d->last_database_message_id); if (*it != nullptr && ((*it)->message_id == d->last_database_message_id || (*it)->have_next)) { + MessageId new_last_database_message_id = d->last_database_message_id; while (*it != nullptr) { auto message_id = (*it)->message_id; - if ((message_id.is_server() || message_id.is_local()) && message_id > d->last_database_message_id) { - set_dialog_last_database_message_id(d, message_id, "on_get_history 2"); - is_dialog_updated = true; + if ((message_id.is_server() || message_id.is_local()) && message_id > new_last_database_message_id) { + new_last_database_message_id = message_id; } ++it; } + if (new_last_database_message_id != d->last_database_message_id) { + set_dialog_last_database_message_id(d, new_last_database_message_id, "on_get_history 2"); + } } } } @@ -8974,10 +8978,6 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ first_message_id = first_added_message_id; } } - - if (is_dialog_updated) { - on_dialog_updated(dialog_id, "on_get_history"); - } } }