diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 069255a9..21dff86e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2260,8 +2260,8 @@ storageStatisticsByChat chat_id:int53 size:int53 count:int32 by_file_type:vector //@description Contains the exact storage usage statistics split by chats and file type @size Total size of files @count Total number of files @by_chat Statistics split by chats storageStatistics size:int53 count:int32 by_chat:vector = StorageStatistics; -//@description Contains approximate storage usage statistics, excluding files of unknown file type @files_size Approximate total size of files @file_count Approximate number of files @database_size Size of the database -storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 = StorageStatisticsFast; +//@description Contains approximate storage usage statistics, excluding files of unknown file type @files_size Approximate total size of files @file_count Approximate number of files @database_size Size of the database @log_size Size of the TDLib interna log +storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 log_size:int53 = StorageStatisticsFast; //@description Contains database statistics //@statistics Database statistics in an unspecified human-readable format diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 8414d58d..e1458e7b 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index d70c00d5..d5804356 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -70,7 +70,7 @@ void StorageManager::get_storage_stats(int32 dialog_limit, Promise pr } void StorageManager::get_storage_stats_fast(Promise promise) { - promise.set_value(FileStatsFast(fast_stat_.size, fast_stat_.cnt, get_db_size())); + promise.set_value(FileStatsFast(fast_stat_.size, fast_stat_.cnt, get_database_size(), get_log_size())); } void StorageManager::get_database_stats(Promise promise) { @@ -145,21 +145,27 @@ void StorageManager::on_all_files(Result r_file_stats, bool dummy) { })); } -int64 StorageManager::get_db_size() { +int64 StorageManager::get_file_size(CSlice path) { + auto r_info = stat(path); + if (r_info.is_error()) { + return 0; + } + + auto size = r_info.ok().size_; + LOG(DEBUG) << "Add file \"" << path << "\" of size " << size << " to fast storage statistics"; + return size; +} + +int64 StorageManager::get_database_size() { int64 size = 0; - auto add_path = [&](CSlice path) { - TRY_RESULT(info, stat(path)); + G()->td_db()->with_db_path([&size](CSlice path) { size += get_file_size(path); }); + return size; +} - LOG(DEBUG) << "Add database file \"" << path << "\" of size " << info.size_ - << " to database storage size statistics"; - size += info.size_; - - return Status::OK(); - }; - - G()->td_db()->with_db_path([&](CSlice path) { add_path(path).ignore(); }); +int64 StorageManager::get_log_size() { + int64 size = 0; for (auto &log_path : log_interface->get_file_paths()) { - add_path(log_path).ignore(); + size += get_file_size(log_path); } return size; } diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index c42f669a..67511249 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -62,7 +62,9 @@ class StorageManager : public Actor { void save_fast_stat(); void load_fast_stat(); - static int64 get_db_size(); + static int64 get_database_size(); + static int64 get_log_size(); + static int64 get_file_size(CSlice path); // RefCnt int32 ref_cnt_{1}; diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index 8fc5bb6a..7679521d 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -20,7 +20,7 @@ namespace td { tl_object_ptr FileStatsFast::as_td_api() const { - return make_tl_object(size, count, db_size); + return make_tl_object(size, count, database_size, log_size); } void FileStats::add(StatByType &by_type, FileType file_type, int64 size) { diff --git a/td/telegram/files/FileStats.h b/td/telegram/files/FileStats.h index 3e801bb0..2d3f7d53 100644 --- a/td/telegram/files/FileStats.h +++ b/td/telegram/files/FileStats.h @@ -55,8 +55,10 @@ struct FullFileInfo { struct FileStatsFast { int64 size{0}; int32 count{0}; - int64 db_size{0}; - FileStatsFast(int64 size, int32 count, int64 db_size) : size(size), count(count), db_size(db_size) { + int64 database_size{0}; + int64 log_size{0}; + FileStatsFast(int64 size, int32 count, int64 database_size, int64 log_size) + : size(size), count(count), database_size(database_size), log_size(log_size) { } tl_object_ptr as_td_api() const; };