Use FlatHashMap for random_id_to_message_id.

This commit is contained in:
levlam 2023-07-26 13:38:10 +03:00
parent 968bfc48df
commit 5bc2634d12
2 changed files with 5 additions and 4 deletions

View File

@ -16087,9 +16087,11 @@ void MessagesManager::add_random_id_to_message_id_correspondence(Dialog *d, int6
auto it = d->random_id_to_message_id.find(random_id); auto it = d->random_id_to_message_id.find(random_id);
if (it == d->random_id_to_message_id.end() || it->second.get() < message_id.get()) { if (it == d->random_id_to_message_id.end() || it->second.get() < message_id.get()) {
LOG(INFO) << "Add correspondence from random_id " << random_id << " to " << message_id << " in " << d->dialog_id; LOG(INFO) << "Add correspondence from random_id " << random_id << " to " << message_id << " in " << d->dialog_id;
if (random_id != 0) {
d->random_id_to_message_id[random_id] = message_id; d->random_id_to_message_id[random_id] = message_id;
} }
} }
}
void MessagesManager::delete_random_id_to_message_id_correspondence(Dialog *d, int64 random_id, MessageId message_id) { void MessagesManager::delete_random_id_to_message_id_correspondence(Dialog *d, int64 random_id, MessageId message_id) {
CHECK(d != nullptr); CHECK(d != nullptr);
@ -36390,7 +36392,7 @@ MessageId MessagesManager::get_message_id_by_random_id(Dialog *d, int64 random_i
} }
auto it = d->random_id_to_message_id.find(random_id); auto it = d->random_id_to_message_id.find(random_id);
if (it == d->random_id_to_message_id.end()) { if (it == d->random_id_to_message_id.end()) {
if (G()->use_message_database() && d->dialog_id.get_type() == DialogType::SecretChat) { if (G()->use_message_database() && d->dialog_id.get_type() == DialogType::SecretChat && random_id != 0) {
auto r_value = G()->td_db()->get_message_db_sync()->get_message_by_random_id(d->dialog_id, random_id); auto r_value = G()->td_db()->get_message_db_sync()->get_message_by_random_id(d->dialog_id, random_id);
if (r_value.is_ok()) { if (r_value.is_ok()) {
debug_add_message_to_dialog_fail_reason_ = "not called"; debug_add_message_to_dialog_fail_reason_ = "not called";

View File

@ -1453,8 +1453,7 @@ class MessagesManager final : public Actor {
int32 pending_read_channel_inbox_pts = 0; // for channels only int32 pending_read_channel_inbox_pts = 0; // for channels only
int32 pending_read_channel_inbox_server_unread_count = 0; // for channels only int32 pending_read_channel_inbox_server_unread_count = 0; // for channels only
MessageId pending_read_channel_inbox_max_message_id; // for channels only MessageId pending_read_channel_inbox_max_message_id; // for channels only
std::unordered_map<int64, MessageId, Hash<int64>> FlatHashMap<int64, MessageId> random_id_to_message_id; // for secret chats and yet unsent messages only
random_id_to_message_id; // for secret chats and yet unsent messages only
MessageId last_assigned_message_id; // identifier of the last local or yet unsent message, assigned after MessageId last_assigned_message_id; // identifier of the last local or yet unsent message, assigned after
// application start, used to guarantee that all assigned message identifiers // application start, used to guarantee that all assigned message identifiers