Add direct cache for linked channels.
GitOrigin-RevId: 1d994bd0aef96c379312a4be776b7a107cd175da
This commit is contained in:
parent
1a9fe6a40d
commit
b85302f928
@ -3722,9 +3722,9 @@ bool ContactsManager::have_input_peer_channel(const Channel *c, ChannelId channe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!from_linked && c->has_linked_channel) {
|
if (!from_linked && c->has_linked_channel) {
|
||||||
auto channel_full = get_channel_full(channel_id);
|
auto linked_channel_id = get_linked_channel_id(channel_id);
|
||||||
if (channel_full == nullptr || have_input_peer_channel(get_channel(channel_full->linked_channel_id),
|
if (linked_channel_id.is_valid() &&
|
||||||
channel_full->linked_channel_id, access_rights, true)) {
|
have_input_peer_channel(get_channel(linked_channel_id), linked_channel_id, access_rights, true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9866,8 +9866,42 @@ void ContactsManager::on_update_channel_full_invite_link(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContactsManager::remove_linked_channel_id(ChannelId channel_id) {
|
||||||
|
if (!channel_id.is_valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = linked_channel_ids_.find(channel_id);
|
||||||
|
if (it != linked_channel_ids_.end()) {
|
||||||
|
auto channel_id = it->second;
|
||||||
|
linked_channel_ids_.erase(it);
|
||||||
|
linked_channel_ids_.erase(channel_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChannelId ContactsManager::get_linked_channel_id(ChannelId channel_id) const {
|
||||||
|
auto channel_full = get_channel_full(channel_id);
|
||||||
|
if (channel_full != nullptr) {
|
||||||
|
return channel_full->linked_channel_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = linked_channel_ids_.find(channel_id);
|
||||||
|
if (it != linked_channel_ids_.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ChannelId();
|
||||||
|
}
|
||||||
|
|
||||||
void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id,
|
void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id,
|
||||||
ChannelId linked_channel_id) {
|
ChannelId linked_channel_id) {
|
||||||
|
remove_linked_channel_id(channel_id);
|
||||||
|
remove_linked_channel_id(linked_channel_id);
|
||||||
|
if (channel_id.is_valid() && linked_channel_id.is_valid()) {
|
||||||
|
linked_channel_ids_[channel_id] = linked_channel_id;
|
||||||
|
linked_channel_ids_[linked_channel_id] = channel_id;
|
||||||
|
}
|
||||||
|
|
||||||
if (channel_full != nullptr && channel_full->linked_channel_id != linked_channel_id) {
|
if (channel_full != nullptr && channel_full->linked_channel_id != linked_channel_id) {
|
||||||
if (channel_full->linked_channel_id.is_valid()) {
|
if (channel_full->linked_channel_id.is_valid()) {
|
||||||
// remove link from a previously linked channel_full
|
// remove link from a previously linked channel_full
|
||||||
|
@ -1102,6 +1102,9 @@ class ContactsManager : public Actor {
|
|||||||
void on_update_channel_full_bot_user_ids(ChannelFull *channel_full, ChannelId channel_id,
|
void on_update_channel_full_bot_user_ids(ChannelFull *channel_full, ChannelId channel_id,
|
||||||
vector<UserId> &&bot_user_ids);
|
vector<UserId> &&bot_user_ids);
|
||||||
|
|
||||||
|
void remove_linked_channel_id(ChannelId channel_id);
|
||||||
|
ChannelId get_linked_channel_id(ChannelId channel_id) const;
|
||||||
|
|
||||||
static bool speculative_add_count(int32 &count, int32 new_count);
|
static bool speculative_add_count(int32 &count, int32 new_count);
|
||||||
|
|
||||||
void speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count, bool by_me);
|
void speculative_add_channel_participants(ChannelId channel_id, int32 new_participant_count, bool by_me);
|
||||||
@ -1420,6 +1423,8 @@ class ContactsManager : public Actor {
|
|||||||
vector<DialogNearby> users_nearby_;
|
vector<DialogNearby> users_nearby_;
|
||||||
vector<DialogNearby> channels_nearby_;
|
vector<DialogNearby> channels_nearby_;
|
||||||
|
|
||||||
|
std::unordered_map<ChannelId, ChannelId, ChannelIdHash> linked_channel_ids_;
|
||||||
|
|
||||||
std::unordered_set<UserId, UserIdHash> restricted_user_ids_;
|
std::unordered_set<UserId, UserIdHash> restricted_user_ids_;
|
||||||
std::unordered_set<ChannelId, ChannelIdHash> restricted_channel_ids_;
|
std::unordered_set<ChannelId, ChannelIdHash> restricted_channel_ids_;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user