Don't load ChannelFull from database in invalidate_channel_full.

This commit is contained in:
levlam 2021-05-09 03:21:18 +03:00
parent 25a6cb07bc
commit 4a13e791bb
2 changed files with 27 additions and 9 deletions

View File

@ -9622,6 +9622,10 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
}
}
if (invalidated_channels_full_.erase(channel_id) > 0) {
do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled);
}
td_->group_call_manager_->on_update_dialog_about(DialogId(channel_id), channel_full->description, false);
send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(channel_id),
@ -10451,6 +10455,8 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
return promise.set_value(Unit());
}
invalidated_channels_full_.erase(channel_id);
if (!G()->close_flag()) {
auto channel_full = get_channel_full(channel_id, "on_get_channel_full");
if (channel_full != nullptr) {
@ -12035,18 +12041,27 @@ void ContactsManager::drop_channel_photos(ChannelId channel_id, bool is_empty, b
void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool need_drop_slow_mode_delay) {
LOG(INFO) << "Invalidate supergroup full for " << channel_id;
// drop channel full cache
auto channel_full = get_channel_full_force(channel_id, "invalidate_channel_full");
auto channel_full = get_channel_full(channel_id, "invalidate_channel_full"); // must not load ChannelFull
if (channel_full != nullptr) {
do_invalidate_channel_full(channel_full, need_drop_slow_mode_delay);
update_channel_full(channel_full, channel_id);
} else {
invalidated_channels_full_.insert(channel_id);
}
}
void ContactsManager::do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay) {
CHECK(channel_full != nullptr);
if (channel_full->expires_at >= Time::now()) {
channel_full->expires_at = 0.0;
channel_full->need_save_to_database = true;
}
if (need_drop_slow_mode_delay && channel_full->slow_mode_delay != 0) {
channel_full->slow_mode_delay = 0;
channel_full->slow_mode_next_send_date = 0;
channel_full->is_slow_mode_next_send_date_changed = true;
channel_full->is_changed = true;
}
update_channel_full(channel_full, channel_id);
}
}
void ContactsManager::on_update_chat_full_photo(ChatFull *chat_full, ChatId chat_id, Photo photo) {

View File

@ -1264,6 +1264,8 @@ class ContactsManager : public Actor {
void drop_channel_photos(ChannelId channel_id, bool is_empty, bool drop_channel_full_photo, const char *source);
void do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay);
void update_user_online_member_count(User *u);
void update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server);
void update_channel_online_member_count(ChannelId channel_id, bool is_from_server);
@ -1589,6 +1591,7 @@ class ContactsManager : public Actor {
std::unordered_map<ChannelId, unique_ptr<Channel>, ChannelIdHash> channels_;
std::unordered_map<ChannelId, unique_ptr<ChannelFull>, ChannelIdHash> channels_full_;
mutable std::unordered_set<ChannelId, ChannelIdHash> unknown_channels_;
std::unordered_set<ChannelId, ChannelIdHash> invalidated_channels_full_;
std::unordered_map<ChannelId, FileSourceId, ChannelIdHash> channel_full_file_source_ids_;
std::unordered_map<SecretChatId, unique_ptr<SecretChat>, SecretChatIdHash> secret_chats_;