From 2898c8909b4af634820673a38f65a2217391bc17 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 26 Apr 2019 01:47:25 +0300 Subject: [PATCH] Add language_pack_database_size to storageStatisticsFast. GitOrigin-RevId: 6c11b5b88edd470da8abe2a0459a9067c3cb6d21 --- benchmark/bench_tddb.cpp | 1 + td/generate/scheme/td_api.tl | 5 +++-- td/generate/scheme/td_api.tlo | Bin 151504 -> 151556 bytes td/telegram/StorageManager.cpp | 14 +++++++++++++- td/telegram/StorageManager.h | 1 + td/telegram/TdDb.cpp | 1 + td/telegram/files/FileDb.cpp | 1 + td/telegram/files/FileStats.cpp | 3 ++- td/telegram/files/FileStats.h | 9 +++++++-- tddb/td/db/SqliteDb.h | 1 + test/db.cpp | 1 + 11 files changed, 31 insertions(+), 6 deletions(-) diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index d997c523b..3c8d485d3 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -14,6 +14,7 @@ #include "td/actor/PromiseFuture.h" #include "td/db/SqliteConnectionSafe.h" +#include "td/db/SqliteDb.h" #include "td/utils/benchmark.h" #include "td/utils/buffer.h" diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f849de67c..4ab660722 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2264,8 +2264,9 @@ 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 @log_size Size of the TDLib interna log -storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 log_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 @language_pack_database_size Size of the language pack database @log_size Size of the TDLib internal log +storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 language_pack_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 26d93b75bc64a701a48d0f9e9690cb712a8c3e3c..b9db2cdea88d5c090f6152b8c33f992c965e359d 100644 GIT binary patch delta 115 zcmcaGpR;8F=Y|9FY>66*g^bAJ*xz z!Hnh8Z@goaU@6Y5N}asnmE`oP!Hnu)wc8H_GsdiufGK7Gf+A-&9S+;JgCMc3CQNhu E0rSi%f&c&j delta 101 zcmZo!zpH;+YW-nwq`KR@dp6kDJ!Y~ diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index f7fe2ca2e..45979190b 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -15,6 +15,8 @@ #include "td/telegram/MessagesManager.h" #include "td/telegram/TdDb.h" +#include "td/db/SqliteDb.h" + #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/Clocks.h" @@ -68,7 +70,8 @@ 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_database_size(), get_log_size())); + promise.set_value(FileStatsFast(fast_stat_.size, fast_stat_.cnt, get_database_size(), + get_language_pack_database_size(), get_log_size())); } void StorageManager::get_database_stats(Promise promise) { @@ -160,6 +163,15 @@ int64 StorageManager::get_database_size() { return size; } +int64 StorageManager::get_language_pack_database_size() { + int64 size = 0; + auto path = G()->shared_config().get_option_string("language_pack_database_path"); + if (!path.empty()) { + SqliteDb::with_db_path(path, [&size](CSlice path) { size += get_file_size(path); }); + } + return size; +} + int64 StorageManager::get_log_size() { int64 size = 0; for (auto &log_path : log_interface->get_file_paths()) { diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index 11c41fd66..2df9506ef 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -62,6 +62,7 @@ class StorageManager : public Actor { void save_fast_stat(); void load_fast_stat(); static int64 get_database_size(); + static int64 get_language_pack_database_size(); static int64 get_log_size(); static int64 get_file_size(CSlice path); diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index d3226cac7..726b6eff4 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -21,6 +21,7 @@ #include "td/db/binlog/ConcurrentBinlog.h" #include "td/db/BinlogKeyValue.h" #include "td/db/SqliteConnectionSafe.h" +#include "td/db/SqliteDb.h" #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueAsync.h" #include "td/db/SqliteKeyValueSafe.h" diff --git a/td/telegram/files/FileDb.cpp b/td/telegram/files/FileDb.cpp index 476785626..3b98c77bb 100644 --- a/td/telegram/files/FileDb.cpp +++ b/td/telegram/files/FileDb.cpp @@ -15,6 +15,7 @@ #include "td/actor/actor.h" #include "td/db/SqliteConnectionSafe.h" +#include "td/db/SqliteDb.h" #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueSafe.h" diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index 7679521dd..7cc069347 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -20,7 +20,8 @@ namespace td { tl_object_ptr FileStatsFast::as_td_api() const { - return make_tl_object(size, count, database_size, log_size); + return make_tl_object(size, count, database_size, language_pack_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 2d3f7d53d..38ca35caa 100644 --- a/td/telegram/files/FileStats.h +++ b/td/telegram/files/FileStats.h @@ -56,9 +56,14 @@ struct FileStatsFast { int64 size{0}; int32 count{0}; int64 database_size{0}; + int64 language_pack_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) { + FileStatsFast(int64 size, int32 count, int64 database_size, int64 language_pack_database_size, int64 log_size) + : size(size) + , count(count) + , database_size(database_size) + , language_pack_database_size(language_pack_database_size) + , log_size(log_size) { } tl_object_ptr as_td_api() const; }; diff --git a/tddb/td/db/SqliteDb.h b/tddb/td/db/SqliteDb.h index 35a15864b..474a5900f 100644 --- a/tddb/td/db/SqliteDb.h +++ b/tddb/td/db/SqliteDb.h @@ -83,4 +83,5 @@ class SqliteDb { bool is_encrypted(); }; + } // namespace td diff --git a/test/db.cpp b/test/db.cpp index 71e077726..962ba4891 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -9,6 +9,7 @@ #include "td/db/BinlogKeyValue.h" #include "td/db/SeqKeyValue.h" #include "td/db/SqliteConnectionSafe.h" +#include "td/db/SqliteDb.h" #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueSafe.h" #include "td/db/TsSeqKeyValue.h"