Remove legacy message LRU deletion.

This commit is contained in:
levlam 2021-12-18 23:26:05 +03:00
parent a3ba653690
commit 6abdb73512
2 changed files with 2 additions and 71 deletions

View File

@ -184,9 +184,6 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te
, tqueue_id_(tqueue_id)
, parameters_(std::move(parameters))
, stat_actor_(std::move(stat_actor)) {
messages_lru_root_.lru_next = &messages_lru_root_;
messages_lru_root_.lru_prev = &messages_lru_root_;
static auto is_inited = init_methods();
CHECK(is_inited);
}
@ -3505,7 +3502,6 @@ ServerBotInfo Client::get_bot_info() const {
void Client::start_up() {
start_time_ = td::Time::now();
next_bot_updates_warning_time_ = start_time_ + 600;
schedule_next_delete_messages_lru();
webhook_set_time_ = start_time_;
next_allowed_set_webhook_time_ = start_time_;
next_set_webhook_logging_time_ = start_time_;
@ -9462,58 +9458,12 @@ void Client::delete_message(int64 chat_id, int64 message_id, bool only_from_cach
}
auto message_info = it->second.get();
CHECK(message_info->lru_next != nullptr);
message_info->lru_next->lru_prev = message_info->lru_prev;
message_info->lru_prev->lru_next = message_info->lru_next;
set_message_reply_to_message_id(message_info, 0);
messages_.erase(it);
}
void Client::schedule_next_delete_messages_lru() {
CHECK(!next_delete_messages_lru_timeout_.has_timeout());
next_delete_messages_lru_timeout_.set_callback(Client::delete_messages_lru);
next_delete_messages_lru_timeout_.set_callback_data(static_cast<void *>(this));
next_delete_messages_lru_timeout_.set_timeout_in(td::Random::fast(MESSAGES_CACHE_TIME, 2 * MESSAGES_CACHE_TIME));
}
void Client::delete_messages_lru(void *client_void) {
CHECK(client_void != nullptr);
auto client = static_cast<Client *>(client_void);
auto now = td::Time::now();
int32 deleted_message_count = 0;
while (client->messages_lru_root_.lru_next->access_time < now - MESSAGES_CACHE_TIME) {
auto message = client->messages_lru_root_.lru_next;
if (client->yet_unsent_reply_message_ids_.count({message->chat_id, message->id})) {
LOG(DEBUG) << "Force usage of message " << message->id << " in " << message->chat_id;
client->update_message_lru(message);
} else {
client->delete_message(message->chat_id, message->id, true);
deleted_message_count++;
}
}
if (deleted_message_count != 0) {
LOG(DEBUG) << "Delete " << deleted_message_count << " messages from cache";
}
client->schedule_next_delete_messages_lru();
}
void Client::update_message_lru(const MessageInfo *message_info) const {
message_info->access_time = td::Time::now();
if (message_info->lru_next != nullptr) {
message_info->lru_next->lru_prev = message_info->lru_prev;
message_info->lru_prev->lru_next = message_info->lru_next;
}
auto prev = messages_lru_root_.lru_prev;
message_info->lru_prev = prev;
prev->lru_next = message_info;
message_info->lru_next = &messages_lru_root_;
messages_lru_root_.lru_prev = message_info;
}
Client::FullMessageId Client::add_message(object_ptr<td_api::message> &&message, bool force_update_content) {
CHECK(message != nullptr);
CHECK(message->sending_state_ == nullptr);
@ -9530,8 +9480,6 @@ Client::FullMessageId Client::add_message(object_ptr<td_api::message> &&message,
message_info = std::move(it->second);
}
update_message_lru(message_info.get());
message_info->id = message_id;
message_info->chat_id = chat_id;
message_info->date = message->date_;
@ -9673,9 +9621,7 @@ const Client::MessageInfo *Client::get_message(int64 chat_id, int64 message_id)
}
LOG(DEBUG) << "Found message " << message_id << " from chat " << chat_id;
auto result = it->second.get();
update_message_lru(result);
return result;
return it->second.get();
}
Client::MessageInfo *Client::get_message_editable(int64 chat_id, int64 message_id) {
@ -9686,9 +9632,7 @@ Client::MessageInfo *Client::get_message_editable(int64 chat_id, int64 message_i
}
LOG(DEBUG) << "Found message " << message_id << " from chat " << chat_id;
auto result = it->second.get();
update_message_lru(result);
return result;
return it->second.get();
}
td::string Client::get_chat_member_status(const object_ptr<td_api::ChatMemberStatus> &status) {

View File

@ -15,7 +15,6 @@
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SignalSlot.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
@ -65,8 +64,6 @@ class Client : public WebhookActor::Callback {
static constexpr int32 MAX_CONCURRENTLY_SENT_CHAT_MESSAGES = 1000; // some unreasonably big value
static constexpr int32 MESSAGES_CACHE_TIME = 3600;
static constexpr std::size_t MIN_PENDING_UPDATES_WARNING = 200;
static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001;
@ -657,10 +654,6 @@ class Client : public WebhookActor::Callback {
td::string get_chat_description(int64 chat_id) const;
struct MessageInfo {
mutable double access_time = 1e20;
mutable const MessageInfo *lru_next = nullptr;
mutable const MessageInfo *lru_prev = nullptr;
int64 id = 0;
int64 sender_user_id = 0;
int64 sender_chat_id = 0;
@ -722,9 +715,6 @@ class Client : public WebhookActor::Callback {
void remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache);
void delete_message(int64 chat_id, int64 message_id, bool only_from_cache);
static void delete_messages_lru(void *client_void);
void schedule_next_delete_messages_lru();
void update_message_lru(const MessageInfo *message_info) const;
void add_new_message(object_ptr<td_api::message> &&message, bool is_edited);
void process_new_message_queue(int64 chat_id);
@ -871,7 +861,6 @@ class Client : public WebhookActor::Callback {
static std::unordered_map<td::string, Status (Client::*)(PromisedQueryPtr &query)> methods_;
MessageInfo messages_lru_root_;
std::unordered_map<FullMessageId, std::unique_ptr<MessageInfo>, FullMessageIdHash> messages_; // message cache
std::unordered_map<int64, UserInfo> users_; // user info cache
std::unordered_map<int64, GroupInfo> groups_; // group info cache
@ -883,8 +872,6 @@ class Client : public WebhookActor::Callback {
std::unordered_map<FullMessageId, std::unordered_set<int64>, FullMessageIdHash>
yet_unsent_reply_message_ids_; // message -> replies to it
td::Timeout next_delete_messages_lru_timeout_;
std::unordered_map<int32, td::vector<PromisedQueryPtr>> file_download_listeners_;
std::unordered_set<int32> download_started_file_ids_;