Add explicit limit on the number of saved auth notifications.

This commit is contained in:
levlam 2022-08-01 01:39:09 +03:00
parent d9cfcf88fe
commit 3f1e0a9317
2 changed files with 18 additions and 0 deletions

View File

@ -6474,6 +6474,19 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
return;
}
old_date = date;
if (auth_notification_id_date_.size() > MAX_SAVED_AUTH_NOTIFICATION_IDS) {
auto min_date = date + 1;
const string *min_key = nullptr;
for (const auto &it : auth_notification_id_date_) {
if (it.second < min_date) {
min_date = it.second;
min_key = &it.first;
}
}
CHECK(min_key != nullptr);
auth_notification_id_date_.erase(*min_key);
}
}
bool is_authorized = td_->auth_manager_->is_authorized();
@ -13419,6 +13432,10 @@ void MessagesManager::init() {
is_changed = true;
continue;
}
if (auth_notification_id_date_.size() == MAX_SAVED_AUTH_NOTIFICATION_IDS) {
is_changed = true;
break;
}
auth_notification_id_date_.emplace(std::move(ids[i]), date);
}
if (is_changed) {

View File

@ -1786,6 +1786,7 @@ class MessagesManager final : public Actor {
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME = 3 * 86400;
static constexpr int32 USERNAME_CACHE_EXPIRE_TIME_SHORT = 900;
static constexpr int32 AUTH_NOTIFICATION_ID_CACHE_TIME = 7 * 86400;
static constexpr size_t MAX_SAVED_AUTH_NOTIFICATION_IDS = 100;
static constexpr int32 ONLINE_MEMBER_COUNT_UPDATE_TIME = 5 * 60;