From 5801d6c695ab7503488d5cdc692203ad905402cb Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 11 Dec 2021 23:03:11 +0300 Subject: [PATCH] Improve FileGcParameters field names. --- td/telegram/StorageManager.cpp | 6 ++--- td/telegram/files/FileGcParameters.cpp | 36 +++++++++++++------------- td/telegram/files/FileGcParameters.h | 16 ++++++------ td/telegram/files/FileGcWorker.cpp | 26 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index 11384ad1c..48c0a5305 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -117,8 +117,8 @@ void StorageManager::run_gc(FileGcParameters parameters, bool return_deleted_fil close_gc_worker(); } - bool split_by_owner_dialog_id = !parameters.owner_dialog_ids.empty() || - !parameters.exclude_owner_dialog_ids.empty() || parameters.dialog_limit != 0; + bool split_by_owner_dialog_id = !parameters.owner_dialog_ids_.empty() || + !parameters.exclude_owner_dialog_ids_.empty() || parameters.dialog_limit_ != 0; get_storage_stats( true /*need_all_files*/, split_by_owner_dialog_id, PromiseCreator::lambda( @@ -156,7 +156,7 @@ void StorageManager::create_stats_worker() { } void StorageManager::on_all_files(FileGcParameters gc_parameters, Result r_file_stats) { - int32 dialog_limit = gc_parameters.dialog_limit; + int32 dialog_limit = gc_parameters.dialog_limit_; if (is_closed_ && r_file_stats.is_ok()) { r_file_stats = Global::request_aborted_error(); } diff --git a/td/telegram/files/FileGcParameters.cpp b/td/telegram/files/FileGcParameters.cpp index 52129d8b8..2d790c937 100644 --- a/td/telegram/files/FileGcParameters.cpp +++ b/td/telegram/files/FileGcParameters.cpp @@ -17,32 +17,32 @@ namespace td { FileGcParameters::FileGcParameters(int64 size, int32 ttl, int32 count, int32 immunity_delay, vector file_types, vector owner_dialog_ids, vector exclude_owner_dialog_ids, int32 dialog_limit) - : file_types(std::move(file_types)) - , owner_dialog_ids(std::move(owner_dialog_ids)) - , exclude_owner_dialog_ids(std::move(exclude_owner_dialog_ids)) - , dialog_limit(dialog_limit) { + : file_types_(std::move(file_types)) + , owner_dialog_ids_(std::move(owner_dialog_ids)) + , exclude_owner_dialog_ids_(std::move(exclude_owner_dialog_ids)) + , dialog_limit_(dialog_limit) { auto &config = G()->shared_config(); - this->max_files_size = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10; + max_files_size_ = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10; - this->max_time_from_last_access = + max_time_from_last_access_ = ttl >= 0 ? ttl : narrow_cast(config.get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23)); - this->max_file_count = - count >= 0 ? count : narrow_cast(config.get_option_integer("storage_max_file_count", 40000)); + max_file_count_ = count >= 0 ? count : narrow_cast(config.get_option_integer("storage_max_file_count", 40000)); - this->immunity_delay = immunity_delay >= 0 - ? immunity_delay - : narrow_cast(config.get_option_integer("storage_immunity_delay", 60 * 60)); + immunity_delay_ = immunity_delay >= 0 + ? immunity_delay + : narrow_cast(config.get_option_integer("storage_immunity_delay", 60 * 60)); } StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters ¶meters) { - return string_builder << "FileGcParameters[" << tag("max_files_size", parameters.max_files_size) - << tag("max_time_from_last_access", parameters.max_time_from_last_access) - << tag("max_file_count", parameters.max_file_count) - << tag("immunity_delay", parameters.immunity_delay) << tag("file_types", parameters.file_types) - << tag("owner_dialog_ids", parameters.owner_dialog_ids) - << tag("exclude_owner_dialog_ids", parameters.exclude_owner_dialog_ids) - << tag("dialog_limit", parameters.dialog_limit) << ']'; + return string_builder << "FileGcParameters[" << tag("max_files_size", parameters.max_files_size_) + << tag("max_time_from_last_access", parameters.max_time_from_last_access_) + << tag("max_file_count", parameters.max_file_count_) + << tag("immunity_delay", parameters.immunity_delay_) + << tag("file_types", parameters.file_types_) + << tag("owner_dialog_ids", parameters.owner_dialog_ids_) + << tag("exclude_owner_dialog_ids", parameters.exclude_owner_dialog_ids_) + << tag("dialog_limit", parameters.dialog_limit_) << ']'; } } // namespace td diff --git a/td/telegram/files/FileGcParameters.h b/td/telegram/files/FileGcParameters.h index 4c074a6ed..a8471a5ed 100644 --- a/td/telegram/files/FileGcParameters.h +++ b/td/telegram/files/FileGcParameters.h @@ -20,16 +20,16 @@ struct FileGcParameters { FileGcParameters(int64 size, int32 ttl, int32 count, int32 immunity_delay, vector file_types, vector owner_dialog_ids, vector exclude_owner_dialog_ids, int32 dialog_limit); - int64 max_files_size; - uint32 max_time_from_last_access; - uint32 max_file_count; - uint32 immunity_delay; + int64 max_files_size_; + uint32 max_time_from_last_access_; + uint32 max_file_count_; + uint32 immunity_delay_; - vector file_types; - vector owner_dialog_ids; - vector exclude_owner_dialog_ids; + vector file_types_; + vector owner_dialog_ids_; + vector exclude_owner_dialog_ids_; - int32 dialog_limit; + int32 dialog_limit_; }; StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters ¶meters); diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 32cc8b1b4..c3f50fdf0 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -47,9 +47,9 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector(FileType::Background)] = true; } - if (!parameters.file_types.empty()) { + if (!parameters.file_types_.empty()) { std::fill(immune_types.begin(), immune_types.end(), true); - for (auto file_type : parameters.file_types) { + for (auto file_type : parameters.file_types_) { immune_types[narrow_cast(file_type)] = false; } for (int32 i = 0; i < MAX_FILE_TYPE; i++) { @@ -81,8 +81,8 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector(info.mtime_nsec) * 1e-9 > now - parameters.immunity_delay) { + if (static_cast(info.mtime_nsec) * 1e-9 > now - parameters.immunity_delay_) { // new files are immune to gc time_immunity_ignored_cnt++; new_stats.add_copy(info); return true; } - if (static_cast(info.atime_nsec) * 1e-9 < now - parameters.max_time_from_last_access) { + if (static_cast(info.atime_nsec) * 1e-9 < now - parameters.max_time_from_last_access_) { do_remove_file(info); total_removed_size += info.size; remove_by_atime_cnt++; @@ -137,13 +137,13 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector parameters.max_file_count) { - remove_count = files.size() - parameters.max_file_count; + if (files.size() > parameters.max_file_count_) { + remove_count = files.size() - parameters.max_file_count_; } - int64 remove_size = -parameters.max_files_size; + int64 remove_size = -parameters.max_files_size_; for (auto &file : files) { remove_size += file.size; }