Don't send message history requests to database if no returned messages can be added.

This commit is contained in:
levlam 2021-07-21 06:24:02 +03:00
parent bd9a03d7e8
commit a393bc5f71

View File

@ -22251,7 +22251,8 @@ void MessagesManager::get_history_impl(const Dialog *d, MessageId from_message_i
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
}
if (!d->first_database_message_id.is_valid() && !d->have_full_history) {
if ((!d->first_database_message_id.is_valid() || from_message_id <= d->first_database_message_id) &&
!d->have_full_history) {
from_database = false;
}
if (from_database && G()->parameters().use_message_db) {
@ -22302,15 +22303,15 @@ void MessagesManager::load_messages_impl(const Dialog *d, MessageId from_message
only_local = true;
}
bool from_database = (left_tries > 2 || only_local) && G()->parameters().use_message_db;
if (!d->first_database_message_id.is_valid() && !d->have_full_history) {
from_database = false;
}
// TODO do not send requests to database if (from_message_id < d->first_database_message_id ||
if (from_message_id == MessageId()) {
get_history_from_the_end_impl(d, from_database, only_local, std::move(promise));
return;
}
if ((!d->first_database_message_id.is_valid() || from_message_id <= d->first_database_message_id) &&
!d->have_full_history) {
from_database = false;
}
if (offset >= -1) {
// get history before some server or local message
limit = min(max(limit + offset + 1, MAX_GET_HISTORY / 2), MAX_GET_HISTORY);