Optimize adding new files to FileStats.

GitOrigin-RevId: bceb6a4540f45339fed92c1a83b19d1981634836
This commit is contained in:
levlam 2020-03-02 02:55:08 +03:00
parent 0b30530260
commit bd0621eeff
3 changed files with 20 additions and 7 deletions

View File

@ -99,23 +99,23 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
}
if (immune_types[narrow_cast<size_t>(info.file_type)]) {
type_immunity_ignored_cnt++;
new_stats.add(FullFileInfo(info));
new_stats.add_copy(info);
return true;
}
if (td::contains(parameters.exclude_owner_dialog_ids, info.owner_dialog_id)) {
exclude_owner_dialog_id_ignored_cnt++;
new_stats.add(FullFileInfo(info));
new_stats.add_copy(info);
return true;
}
if (!parameters.owner_dialog_ids.empty() && !td::contains(parameters.owner_dialog_ids, info.owner_dialog_id)) {
owner_dialog_id_ignored_cnt++;
new_stats.add(FullFileInfo(info));
new_stats.add_copy(info);
return true;
}
if (info.mtime_nsec * 1e-9 > now - parameters.immunity_delay) {
// new files are immune to gc
time_immunity_ignored_cnt++;
new_stats.add(FullFileInfo(info));
new_stats.add_copy(info);
return true;
}
@ -167,7 +167,7 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
}
while (pos < files.size()) {
new_stats.add(std::move(files[pos]));
new_stats.add_copy(files[pos]);
pos++;
}

View File

@ -31,14 +31,25 @@ void FileStats::add(StatByType &by_type, FileType file_type, int64 size) {
by_type[pos].cnt++;
}
void FileStats::add(FullFileInfo &&info) {
void FileStats::add_impl(const FullFileInfo &info) {
if (split_by_owner_dialog_id) {
add(stat_by_owner_dialog_id[info.owner_dialog_id], info.file_type, info.size);
} else {
add(stat_by_type, info.file_type, info.size);
}
}
void FileStats::add_copy(const FullFileInfo &info) {
add_impl(info);
if (need_all_files) {
all_files.emplace_back(std::move(info));
all_files.push_back(info);
}
}
void FileStats::add(FullFileInfo &&info) {
add_impl(info);
if (need_all_files) {
all_files.push_back(std::move(info));
}
}

View File

@ -79,6 +79,7 @@ struct FileStats {
std::vector<FullFileInfo> all_files;
void add_copy(const FullFileInfo &info);
void add(FullFileInfo &&info);
void apply_dialog_limit(int32 limit);
@ -87,6 +88,7 @@ struct FileStats {
FileTypeStat get_total_nontemp_stat() const;
private:
void add_impl(const FullFileInfo &info);
void add(StatByType &by_type, FileType file_type, int64 size);
};