From 3afbce24b3d237c7a1cb86c83da50b4e97a0672f Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 23 Jul 2022 23:50:28 +0300 Subject: [PATCH] Disable getStorageStatisticsFast for bots to reduce disk usage in the main thread. --- td/telegram/Td.cpp | 5 +++++ td/telegram/files/FileManager.cpp | 12 ++++++++---- td/telegram/files/FileManager.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7baa0b1cb..1b0d8627e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3982,6 +3982,10 @@ void Td::init_file_manager() { explicit FileManagerContext(Td *td) : td_(td) { } + bool need_notify_on_new_files() final { + return !td_->auth_manager_->is_bot(); + } + void on_new_file(int64 size, int64 real_size, int32 cnt) final { send_closure(G()->storage_manager(), &StorageManager::on_new_file, size, real_size, cnt); } @@ -4867,6 +4871,7 @@ void Td::on_request(uint64 id, td_api::getStorageStatistics &request) { } void Td::on_request(uint64 id, td_api::getStorageStatisticsFast &request) { + CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { if (result.is_error()) { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 6dcc7cd37..3474c07dc 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2157,7 +2157,9 @@ void FileManager::delete_file(FileId file_id, Promise promise, const char if (file_view.has_local_location()) { if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) { clear_from_pmc(node); - context_->on_new_file(-file_view.size(), -file_view.get_allocated_local_size(), -1); + if (context_->need_notify_on_new_files()) { + context_->on_new_file(-file_view.size(), -file_view.get_allocated_local_size(), -1); + } path = std::move(node->local_.full().path_); } } else { @@ -3511,7 +3513,7 @@ void FileManager::on_download_ok(QueryId query_id, FullLocalFileLocation local, if (r_new_file_id.is_error()) { status = Status::Error(PSLICE() << "Can't register local file after download: " << r_new_file_id.error().message()); } else { - if (is_new) { + if (is_new && context_->need_notify_on_new_files()) { context_->on_new_file(size, get_file_view(r_new_file_id.ok()).get_allocated_local_size(), 1); } auto r_file_id = merge(r_new_file_id.ok(), file_id); @@ -3684,8 +3686,10 @@ void FileManager::on_generate_ok(QueryId query_id, FullLocalFileLocation local) CHECK(file_node); FileView file_view(file_node); - if (!file_view.has_generate_location() || !begins_with(file_view.generate_location().conversion_, "#file_id#")) { - context_->on_new_file(file_view.size(), file_view.get_allocated_local_size(), 1); + if (context_->need_notify_on_new_files()) { + if (!file_view.has_generate_location() || !begins_with(file_view.generate_location().conversion_, "#file_id#")) { + context_->on_new_file(file_view.size(), file_view.get_allocated_local_size(), 1); + } } run_upload(file_node, {}); diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index e0ac997f7..eb2f00a38 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -382,6 +382,8 @@ class FileManager final : public FileLoadManager::Callback { class Context { public: + virtual bool need_notify_on_new_files() = 0; + virtual void on_new_file(int64 size, int64 real_size, int32 cnt) = 0; virtual void on_file_updated(FileId size) = 0;