Merge commit 'c5549b73460f58addfaea52c0bef98a94483211f'

Conflicts:
	td/telegram/MessagesManager.cpp
This commit is contained in:
Andrea Cavalli 2021-01-08 14:40:25 +01:00
commit 5af21e5612
4 changed files with 55 additions and 22 deletions

View File

@ -13448,7 +13448,7 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
return {};
}
auto is_dialog_participant_suitable = [this](const DialogParticipant &participant, DialogParticipantsFilter filter) {
auto is_dialog_participant_suitable = [this, filter](const DialogParticipant &participant) {
switch (filter.type) {
case DialogParticipantsFilter::Type::Contacts:
return is_user_contact(participant.user_id);
@ -13472,7 +13472,7 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
vector<UserId> user_ids;
for (const auto &participant : chat_full->participants) {
if (is_dialog_participant_suitable(participant, filter)) {
if (is_dialog_participant_suitable(participant)) {
user_ids.push_back(participant.user_id);
}
}

View File

@ -6275,6 +6275,23 @@ void MessagesManager::skip_old_pending_update(tl_object_ptr<telegram_api::Update
<< "Receive useless update " << oneline(to_string(update)) << " from " << source;
}
int32 MessagesManager::get_min_pending_pts() const {
int32 result = std::numeric_limits<int32>::max();
if (!pending_pts_updates_.empty()) {
auto pts = pending_pts_updates_.begin()->first;
if (pts < result) {
result = pts;
}
}
if (!postponed_pts_updates_.empty()) {
auto pts = postponed_pts_updates_.begin()->first;
if (pts < result) {
result = pts;
}
}
return result;
}
void MessagesManager::add_pending_update(tl_object_ptr<telegram_api::Update> &&update, int32 new_pts, int32 pts_count,
bool force_apply, Promise<Unit> &&promise, const char *source) {
// do not try to run getDifference from this function
@ -6380,13 +6397,13 @@ void MessagesManager::add_pending_update(tl_object_ptr<telegram_api::Update> &&u
}
}
if (new_pts <= old_pts) {
if (new_pts <= old_pts || (old_pts >= 1 && new_pts > old_pts + 500000000)) {
skip_old_pending_update(std::move(update), new_pts, old_pts, pts_count, source);
return promise.set_value(Unit());
}
auto old_postponed_pts_updates_behavior
= G()->shared_config().get_option_boolean("experiment_old_postponed_pts_updates_behavior", true);
= G()->shared_config().get_option_boolean("experiment_old_postponed_pts_updates_behavior", false);
if (td_->updates_manager_->running_get_difference() || (!old_postponed_pts_updates_behavior && !postponed_pts_updates_.empty())) {
VLOG(messages) << "Save pending update got while running getDifference from " << source;
if (td_->updates_manager_->running_get_difference()) {
@ -8904,24 +8921,19 @@ void MessagesManager::before_get_difference() {
void MessagesManager::after_get_difference() {
CHECK(!td_->updates_manager_->running_get_difference());
if (!postponed_pts_updates_.empty()) {
LOG(INFO) << "Begin to apply postponed pts updates";
auto old_pts = td_->updates_manager_->get_pts();
for (auto &update : postponed_pts_updates_) {
auto new_pts = update.second.pts;
if (new_pts <= old_pts) {
skip_old_pending_update(std::move(update.second.update), new_pts, old_pts, update.second.pts_count,
"after get difference");
update.second.promise.set_value(Unit());
} else {
VLOG(add_pending_update) << "Calling add_pending_update (8)";
add_pending_update(std::move(update.second.update), update.second.pts, update.second.pts_count, false,
std::move(update.second.promise), "after get difference");
}
if (postponed_pts_updates_.size()) {
auto postponed_updates = std::move(postponed_pts_updates_);
postponed_pts_updates_.clear();
LOG(INFO) << "Begin to apply " << postponed_updates.size() << " postponed pts updates";
for (auto &postponed_update : postponed_updates) {
auto &update = postponed_update.second;
add_pending_update(std::move(update.update), update.pts, update.pts_count, false, std::move(update.promise),
"after get difference");
CHECK(!td_->updates_manager_->running_get_difference());
}
postponed_pts_updates_.clear();
LOG(INFO) << "Finish to apply postponed pts updates";
LOG(INFO) << "Finish to apply postponed pts updates, have " << postponed_pts_updates_.size()
<< " left postponed updates";
}
running_get_difference_ = false;

View File

@ -792,6 +792,8 @@ class MessagesManager : public Actor {
tl_object_ptr<td_api::messages> get_messages_object(int32 total_count, const vector<FullMessageId> &full_message_ids,
bool skip_not_found);
int32 get_min_pending_pts() const;
void add_pending_update(tl_object_ptr<telegram_api::Update> &&update, int32 new_pts, int32 pts_count,
bool force_apply, Promise<Unit> &&promise, const char *source);

View File

@ -183,11 +183,30 @@ void UpdatesManager::tear_down() {
}
void UpdatesManager::fill_pts_gap(void *td) {
fill_gap(td, "pts");
CHECK(td != nullptr);
if (G()->close_flag()) {
return;
}
auto td_ptr = static_cast<Td *>(td);
string source = PSTRING() << "pts from " << td_ptr->updates_manager_->get_pts() << " to "
<< td_ptr->messages_manager_->get_min_pending_pts();
fill_gap(td, source.c_str());
}
void UpdatesManager::fill_seq_gap(void *td) {
fill_gap(td, "seq");
CHECK(td != nullptr);
if (G()->close_flag()) {
return;
}
auto td_ptr = static_cast<Td *>(td);
auto seq = std::numeric_limits<int32>::max();
if (!td_ptr->updates_manager_->pending_seq_updates_.empty()) {
seq = td_ptr->updates_manager_->pending_seq_updates_.begin()->first;
}
string source = PSTRING() << "seq from " << td_ptr->updates_manager_->seq_ << " to " << seq;
fill_gap(td, source.c_str());
}
void UpdatesManager::fill_qts_gap(void *td) {