Fix compilation warnings and errors

This commit is contained in:
Andrea Cavalli 2021-09-10 15:47:26 +02:00
parent a20e8b6db3
commit 37b1d48470
9 changed files with 63 additions and 56 deletions

View File

@ -31,8 +31,8 @@ We added some options:
* **receive_access_hashes** (true/**false**) Receive chats and users access hash as updates
* **experiment_enable_file_reference_cleanup** (**true**/false) During cleanup, free the memory of the file references
* **experiment_enable_chat_access_hash_cleanup** (**true**/false) During cleanup, clean chats and channels access hash
* **enable_reactive_pull_backpressure** (true/**false**) Enable manual `get_channel_difference` execution by calling `getChannelDifference(channel_difference_id)`.
Don't modify this option unless you have a very large bot that struggles to keep up with start-up updates throughput, or you want to implement a backpressure-aware pull-based library.
* **enable_reactive_channel_difference** (true/**false**) Enable manual `get_channel_difference` execution by calling `getChannelDifference(channel_difference_id)`.
Don't modify this option unless you have a very large bot that struggles to keep up with start-up updates throughput, or you want to use a reactive library.
## Custom API functions
### TdApi.OptimizeMemory

View File

@ -12,12 +12,12 @@
should become
```cpp
auto enable_reactive_pull_backpressure
auto enable_reactive_channel_difference
= G()->shared_config()
.get_option_boolean("enable_reactive_pull_backpressure", false);
.get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, old_pts, true,
enable_reactive_pull_backpressure,
enable_reactive_channel_difference,
"add_pending_channel_update pts mismatch");
```

View File

@ -938,6 +938,12 @@ void BackgroundManager::on_reset_background(Result<Unit> &&result, Promise<Unit>
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
reset_backgrounds_data();
promise.set_value(Unit());
}
void BackgroundManager::reset_backgrounds_data() {
installed_backgrounds_.clear();
set_background_id(BackgroundId(), BackgroundType(), false);
set_background_id(BackgroundId(), BackgroundType(), true);
@ -949,8 +955,6 @@ void BackgroundManager::on_reset_background(Result<Unit> &&result, Promise<Unit>
local_background_ids_[1].clear();
save_local_backgrounds(true);
}
promise.set_value(Unit());
}
void BackgroundManager::add_background(const Background &background, bool replace_type) {
@ -1056,7 +1060,7 @@ string BackgroundManager::get_background_name_database_key(const string &name) {
std::pair<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
BackgroundId expected_background_id, const string &expected_background_name,
telegram_api::object_ptr<telegram_api::WallPaper> wallpaper_ptr, bool replace_type) {
if (!(wallpaper_ptr != nullptr)) return BackgroundId();
if (!(wallpaper_ptr != nullptr)) return {};
if (wallpaper_ptr->get_id() == telegram_api::wallPaperNoFile::ID) {
auto wallpaper = move_tl_object_as<telegram_api::wallPaperNoFile>(wallpaper_ptr);
@ -1282,7 +1286,7 @@ void BackgroundManager::memory_cleanup(bool full) {
file_id_to_background_id_.rehash(0);
loaded_from_database_backgrounds_.clear();
loaded_from_database_backgrounds_.rehash(0);
installed_background_ids_.clear();
reset_backgrounds_data();
}
void BackgroundManager::memory_stats(vector<string> &output) {
@ -1296,7 +1300,7 @@ void BackgroundManager::memory_stats(vector<string> &output) {
output.push_back(",");
output.push_back("\"loaded_from_database_backgrounds_\":"); output.push_back(std::to_string(loaded_from_database_backgrounds_.size()));
output.push_back(",");
output.push_back("\"installed_background_ids_\":"); output.push_back(std::to_string(installed_background_ids_.size()));
output.push_back("\"installed_backgrounds_\":"); output.push_back(std::to_string(installed_backgrounds_.size()));
}
} // namespace td

View File

@ -150,6 +150,8 @@ class BackgroundManager final : public Actor {
void on_reset_background(Result<Unit> &&result, Promise<Unit> &&promise);
void reset_backgrounds_data();
void upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme, Promise<Unit> &&promise);
void on_upload_background_file(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);

View File

@ -15850,6 +15850,8 @@ tl_object_ptr<td_api::accessHash> ContactsManager::get_user_access_hash_object(U
tl_object_ptr<td_api::AccessHashType> type = make_tl_object<td_api::accessHashTypeUser>();
DialogId dialog_id(user_id);
return make_tl_object<td_api::accessHash>(dialog_id.get(), std::move(type), u->access_hash);
} else {
return nullptr;
}
}
@ -15861,6 +15863,8 @@ tl_object_ptr<td_api::accessHash> ContactsManager::get_channel_access_hash_objec
tl_object_ptr<td_api::AccessHashType> type = make_tl_object<td_api::accessHashTypeChannel>();
DialogId dialog_id(channel_id);
return make_tl_object<td_api::accessHash>(dialog_id.get(), std::move(type), c->access_hash);
} else {
return nullptr;
}
}
@ -16274,8 +16278,6 @@ void ContactsManager::memory_cleanup(bool full) {
user_photos_.rehash(0);
unknown_users_.clear();
unknown_users_.rehash(0);
pending_user_photos_.clear();
pending_user_photos_.rehash(0);
user_profile_photo_file_source_ids_.clear();
user_profile_photo_file_source_ids_.rehash(0);
my_photo_file_id_.clear();

View File

@ -6936,16 +6936,16 @@ void MessagesManager::on_update_channel_too_long(tl_object_ptr<telegram_api::upd
if (d != nullptr) {
if (update_pts == 0 || update_pts > d->pts) {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference,
"on_update_channel_too_long 1");
}
} else {
if (force_apply) {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, -1, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, -1, true, enable_reactive_channel_difference,
"on_update_channel_too_long 2");
} else {
td_->updates_manager_->schedule_get_difference("on_update_channel_too_long 3");
@ -7021,9 +7021,9 @@ void MessagesManager::update_message_interaction_info(FullMessageId full_message
LOG(INFO) << "Ignore message interaction info about unknown " << full_message_id;
if (!message_id.is_scheduled() && message_id > d->last_new_message_id &&
dialog_id.get_type() == DialogType::Channel) {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference,
"update_message_interaction_info");
}
return;
@ -7599,9 +7599,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
LOG(INFO) << "Found a gap in unknown " << dialog_id << " with pts = " << pts << ". new_pts = " << new_pts
<< ", pts_count = " << pts_count << " in update from " << source;
add_postponed_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise));
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, pts, true, enable_reactive_pull_backpressure, "add_pending_channel_update 3");
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, pts, true, enable_reactive_channel_difference, "add_pending_channel_update 3");
return;
}
@ -7633,9 +7633,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
<< ", update is from " << source << ": " << oneline(to_string(update));
last_channel_pts_jump_warning_time_ = now;
}
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_pull_backpressure, "add_pending_channel_update old");
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_channel_difference, "add_pending_channel_update old");
}
if (update->get_id() == telegram_api::updateNewChannelMessage::ID) {
@ -7681,9 +7681,9 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p
if (d->was_opened || td_->contacts_manager_->get_channel_status(channel_id).is_member() ||
is_dialog_sponsored(d)) {
add_postponed_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise));
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, old_pts, true, enable_reactive_channel_difference,
"add_pending_channel_update pts mismatch");
} else {
promise.set_value(Unit());
@ -11497,9 +11497,9 @@ void MessagesManager::read_channel_message_content_from_updates(Dialog *d, Messa
if (m != nullptr) {
read_message_content(d, m, false, "read_channel_message_content_from_updates");
} else if (message_id > d->last_new_message_id) {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(d->dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(d->dialog_id, d->pts, true, enable_reactive_channel_difference,
"read_channel_message_content_from_updates");
}
}
@ -14865,9 +14865,9 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
send_update_chat_last_message(d, "on_get_dialogs");
}
} else {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference,
"on_get_dialogs");
}
}
@ -29462,9 +29462,9 @@ void MessagesManager::check_send_message_result(int64 random_id, DialogId dialog
return;
}
if (dialog_id.get_type() == DialogType::Channel) {
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference,
"check_send_message_result");
} else {
td_->updates_manager_->schedule_get_difference("check_send_message_result");
@ -33318,14 +33318,14 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
auto next_message = *it;
if (next_message != nullptr) {
if (next_message->message_id.is_server()) {
if (G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false) == false) {
if (G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false) == false) {
LOG(ERROR) << "Attach " << message_id << " from " << source << " before " << next_message->message_id
<< " and after " << previous_message_id << " in " << dialog_id;
dump_debug_message_op(d);
}
}
} else {
if (G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false) == false) {
if (G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false) == false) {
LOG(ERROR) << "Have_next is true, but there is no next message after " << previous_message_id << " from "
<< source << " in " << dialog_id;
dump_debug_message_op(d);
@ -36421,9 +36421,10 @@ void MessagesManager::run_after_channel_difference(DialogId dialog_id, Promise<U
run_after_get_channel_difference_[dialog_id].push_back(std::move(promise));
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d == nullptr ? load_channel_pts(dialog_id) : d->pts, true, enable_reactive_pull_backpressure,
const Dialog *d = get_dialog(dialog_id);
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d == nullptr ? load_channel_pts(dialog_id) : d->pts, true, enable_reactive_channel_difference,
"run_after_channel_difference");
}
@ -36442,9 +36443,9 @@ void MessagesManager::on_channel_get_difference_timeout(DialogId dialog_id) {
LOG(ERROR) << "Unknown dialog " << dialog_id;
return;
}
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure,
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference,
"on_channel_get_difference_timeout");
}
@ -36474,8 +36475,8 @@ class MessagesManager::GetChannelDifferenceLogEvent {
};
void MessagesManager::get_channel_difference_delayed(DialogId dialog_id, int32 pts,
bool force, bool enable_reactive_pull_backpressure, const char *source) {
if (!enable_reactive_pull_backpressure) {
bool force, bool enable_reactive_channel_difference, const char *source) {
if (!enable_reactive_channel_difference) {
// Execute get_channel_difference immediatly
const char* source_prefix = "on_get_channel_difference, ";
char* joined_source{ new char[strlen(source_prefix) + strlen(source) + 1] };
@ -37067,9 +37068,9 @@ void MessagesManager::on_get_channel_difference(
if (!is_final) {
LOG_IF(ERROR, timeout > 0) << "Have timeout in nonfinal ChannelDifference in " << dialog_id;
auto enable_reactive_pull_backpressure
= G()->shared_config().get_option_boolean("enable_reactive_pull_backpressure", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_pull_backpressure, "on_get_channel_difference");
auto enable_reactive_channel_difference
= G()->shared_config().get_option_boolean("enable_reactive_channel_difference", false);
get_channel_difference_delayed(dialog_id, d->pts, true, enable_reactive_channel_difference, "on_get_channel_difference");
return;
}

View File

@ -2898,7 +2898,7 @@ class MessagesManager final : public Actor {
void on_channel_get_difference_timeout(DialogId dialog_id);
void get_channel_difference_delayed(DialogId dialog_id, int32 pts, bool force, bool enable_reactive_pull_backpressure,
void get_channel_difference_delayed(DialogId dialog_id, int32 pts, bool force, bool enable_reactive_channel_difference,
const char *source);
void get_channel_difference(DialogId dialog_id, int32 pts, bool force, const char *source);

View File

@ -1737,8 +1737,6 @@ void PollManager::memory_cleanup(bool full) {
polls_.rehash(0);
poll_messages_.clear();
poll_messages_.rehash(0);
pending_answers_.clear();
pending_answers_.rehash(0);
poll_voters_.clear();
poll_voters_.rehash(0);
loaded_from_database_polls_.clear();

View File

@ -7652,7 +7652,7 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
if (set_boolean_option("experiment_old_postponed_pts_updates_behavior")) {
return;
}
if (set_boolean_option("enable_reactive_pull_backpressure")) {
if (set_boolean_option("enable_reactive_channel_difference")) {
return;
}
break;