Disable getStorageStatisticsFast for bots to reduce disk usage in the main thread.
This commit is contained in:
parent
2729d44f71
commit
3afbce24b3
@ -3982,6 +3982,10 @@ void Td::init_file_manager() {
|
|||||||
explicit FileManagerContext(Td *td) : td_(td) {
|
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 {
|
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);
|
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) {
|
void Td::on_request(uint64 id, td_api::getStorageStatisticsFast &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<FileStatsFast> result) mutable {
|
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<FileStatsFast> result) mutable {
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
|
@ -2157,7 +2157,9 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
|
|||||||
if (file_view.has_local_location()) {
|
if (file_view.has_local_location()) {
|
||||||
if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) {
|
if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) {
|
||||||
clear_from_pmc(node);
|
clear_from_pmc(node);
|
||||||
|
if (context_->need_notify_on_new_files()) {
|
||||||
context_->on_new_file(-file_view.size(), -file_view.get_allocated_local_size(), -1);
|
context_->on_new_file(-file_view.size(), -file_view.get_allocated_local_size(), -1);
|
||||||
|
}
|
||||||
path = std::move(node->local_.full().path_);
|
path = std::move(node->local_.full().path_);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -3511,7 +3513,7 @@ void FileManager::on_download_ok(QueryId query_id, FullLocalFileLocation local,
|
|||||||
if (r_new_file_id.is_error()) {
|
if (r_new_file_id.is_error()) {
|
||||||
status = Status::Error(PSLICE() << "Can't register local file after download: " << r_new_file_id.error().message());
|
status = Status::Error(PSLICE() << "Can't register local file after download: " << r_new_file_id.error().message());
|
||||||
} else {
|
} 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);
|
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);
|
auto r_file_id = merge(r_new_file_id.ok(), file_id);
|
||||||
@ -3684,9 +3686,11 @@ void FileManager::on_generate_ok(QueryId query_id, FullLocalFileLocation local)
|
|||||||
CHECK(file_node);
|
CHECK(file_node);
|
||||||
|
|
||||||
FileView file_view(file_node);
|
FileView file_view(file_node);
|
||||||
|
if (context_->need_notify_on_new_files()) {
|
||||||
if (!file_view.has_generate_location() || !begins_with(file_view.generate_location().conversion_, "#file_id#")) {
|
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);
|
context_->on_new_file(file_view.size(), file_view.get_allocated_local_size(), 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
run_upload(file_node, {});
|
run_upload(file_node, {});
|
||||||
|
|
||||||
|
@ -382,6 +382,8 @@ class FileManager final : public FileLoadManager::Callback {
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
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_new_file(int64 size, int64 real_size, int32 cnt) = 0;
|
||||||
|
|
||||||
virtual void on_file_updated(FileId size) = 0;
|
virtual void on_file_updated(FileId size) = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user