Add optimize_memory command

This commit is contained in:
Andrea Cavalli 2020-11-05 13:12:05 +01:00
parent e6424b5a09
commit f4e3987860
4 changed files with 44 additions and 4 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@
**/.*.swp
**/.DS_Store
bin/
vcpkg/
vcpkg/
/.idea/

View File

@ -8,6 +8,8 @@ TDLight Telegram Bot API is 100% compatible with the official version.
### TDLib replaced with TDLight
[TDLight](https://github.com/tdlight-team/tdlight) provides constant memory usage, unlike tdlib that must be restarted to reduce the heap size.
### Command `optimize_memory`
Calling `optimize_memory` will remove old data from the in-memory cache and give the freed memory back to the os
-----

View File

@ -227,6 +227,7 @@ bool Client::init_methods() {
methods_.emplace("getchatadministrators", &Client::process_get_chat_administrators_query);
methods_.emplace("getchatmembercount", &Client::process_get_chat_member_count_query);
methods_.emplace("getchatmemberscount", &Client::process_get_chat_member_count_query);
methods_.emplace("optimizememory", &Client::process_optimize_memory_query);
methods_.emplace("leavechat", &Client::process_leave_chat_query);
methods_.emplace("promotechatmember", &Client::process_promote_chat_member_query);
methods_.emplace("setchatadministratorcustomtitle", &Client::process_set_chat_administrator_custom_title_query);
@ -3782,14 +3783,44 @@ void Client::on_update_authorization_state() {
send_request(make_object<td_api::setOption>("disable_time_adjustment_protection",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("disable_minithumbnails",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("disable_document_filenames",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("disable_notifications",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("ignore_update_chat_last_message",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("ignore_update_chat_read_inbox",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("ignore_update_user_chat_action",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("ignore_server_deletes_and_reads",
make_object<td_api::optionValueBoolean>(true)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("delete_chat_reference_after_seconds",
make_object<td_api::optionValueInteger>(3600)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("delete_user_reference_after_seconds",
make_object<td_api::optionValueInteger>(3600)),
std::make_unique<TdOnOkCallback>());
send_request(make_object<td_api::setOption>("delete_file_reference_after_seconds",
make_object<td_api::optionValueInteger>(3600)),
std::make_unique<TdOnOkCallback>());
auto parameters = make_object<td_api::tdlibParameters>();
parameters->use_test_dc_ = is_test_dc_;
parameters->database_directory_ = dir_;
//parameters->use_file_database_ = false;
//parameters->use_chat_info_database_ = false;
//parameters->use_secret_chats_ = false;
parameters->use_file_database_ = false;
parameters->use_chat_info_database_ = false;
parameters->use_secret_chats_ = false;
parameters->use_message_database_ = USE_MESSAGE_DATABASE;
parameters->api_id_ = parameters_->api_id_;
parameters->api_hash_ = parameters_->api_hash_;
@ -6872,6 +6903,11 @@ td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query)
return Status::OK();
}
td::Status Client::process_optimize_memory_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::optimizeMemory>(), std::make_unique<TdOnOkQueryCallback>(std::move(query)));
return Status::OK();
}
td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) {
auto chat_id = query->arg("chat_id");

View File

@ -453,6 +453,7 @@ class Client : public WebhookActor::Callback {
Status process_get_chat_member_query(PromisedQueryPtr &query);
Status process_get_chat_administrators_query(PromisedQueryPtr &query);
Status process_get_chat_member_count_query(PromisedQueryPtr &query);
Status process_optimize_memory_query(PromisedQueryPtr &query);
Status process_leave_chat_query(PromisedQueryPtr &query);
Status process_promote_chat_member_query(PromisedQueryPtr &query);
Status process_set_chat_administrator_custom_title_query(PromisedQueryPtr &query);