Unload at most 5000 messages at a time.

This commit is contained in:
levlam 2022-11-11 16:06:05 +03:00
parent e8b8f3eb88
commit f670d646c9
2 changed files with 9 additions and 2 deletions

View File

@ -11665,6 +11665,10 @@ void MessagesManager::find_unloadable_messages(const Dialog *d, int32 unload_bef
if (m == nullptr) {
return;
}
if (message_ids.size() >= MAX_UNLOADED_MESSAGES) {
has_left_to_unload_messages = true;
return;
}
find_unloadable_messages(d, unload_before_date, m->left.get(), message_ids, has_left_to_unload_messages);
@ -11980,7 +11984,9 @@ void MessagesManager::unload_dialog(DialogId dialog_id) {
if (has_left_to_unload_messages) {
LOG(DEBUG) << "Need to unload more messages in " << dialog_id;
pending_unload_dialog_timeout_.add_timeout_in(d->dialog_id.get(), get_next_unload_dialog_delay(d));
pending_unload_dialog_timeout_.add_timeout_in(
d->dialog_id.get(),
to_unload_message_ids.size() >= MAX_UNLOADED_MESSAGES ? 1.0 : get_next_unload_dialog_delay(d));
} else {
d->has_unload_timeout = false;
}

View File

@ -1810,7 +1810,8 @@ class MessagesManager final : public Actor {
static constexpr size_t MAX_DIALOG_FILTER_TITLE_LENGTH = 12; // server side limit for dialog filter title
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
static constexpr int32 DIALOG_FILTERS_CACHE_TIME = 86400;
static constexpr size_t MIN_DELETED_ASYNCHRONOUSLY_MESSAGES = 10u;
static constexpr size_t MIN_DELETED_ASYNCHRONOUSLY_MESSAGES = 10;
static constexpr size_t MAX_UNLOADED_MESSAGES = 5000;
static constexpr int64 SPONSORED_DIALOG_ORDER = static_cast<int64>(2147483647) << 32;
static constexpr int32 MIN_PINNED_DIALOG_DATE = 2147000000; // some big date