2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/DialogId.h"
|
2019-01-19 22:54:29 +01:00
|
|
|
#include "td/telegram/files/FileType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace td {
|
2021-09-10 17:23:23 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td_api {
|
|
|
|
class storageStatistics;
|
|
|
|
class storageStatisticsFast;
|
|
|
|
} // namespace td_api
|
|
|
|
|
|
|
|
struct FileTypeStat {
|
|
|
|
int64 size{0};
|
|
|
|
int32 cnt{0};
|
|
|
|
};
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const FileTypeStat &stat, StorerT &storer) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using ::td::store;
|
|
|
|
store(stat.size, storer);
|
|
|
|
store(stat.cnt, storer);
|
|
|
|
}
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(FileTypeStat &stat, ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using ::td::parse;
|
|
|
|
parse(stat.size, parser);
|
|
|
|
parse(stat.cnt, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FullFileInfo {
|
|
|
|
FileType file_type;
|
|
|
|
string path;
|
|
|
|
DialogId owner_dialog_id;
|
|
|
|
int64 size;
|
|
|
|
uint64 atime_nsec;
|
|
|
|
uint64 mtime_nsec;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FileStatsFast {
|
|
|
|
int64 size{0};
|
|
|
|
int32 count{0};
|
2019-04-21 18:22:58 +02:00
|
|
|
int64 database_size{0};
|
2019-04-26 00:47:25 +02:00
|
|
|
int64 language_pack_database_size{0};
|
2019-04-21 18:22:58 +02:00
|
|
|
int64 log_size{0};
|
2019-04-26 00:47:25 +02:00
|
|
|
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) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-06-22 03:28:03 +02:00
|
|
|
tl_object_ptr<td_api::storageStatisticsFast> get_storage_statistics_fast_object() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-09-26 11:44:18 +02:00
|
|
|
class FileStats {
|
|
|
|
bool need_all_files_{false};
|
|
|
|
bool split_by_owner_dialog_id_{false};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-06-22 01:27:58 +02:00
|
|
|
using StatByType = std::array<FileTypeStat, MAX_FILE_TYPE>;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-26 11:44:18 +02:00
|
|
|
StatByType stat_by_type_;
|
|
|
|
std::unordered_map<DialogId, StatByType, DialogIdHash> stat_by_owner_dialog_id_;
|
|
|
|
vector<FullFileInfo> all_files_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-26 11:44:18 +02:00
|
|
|
void add_impl(const FullFileInfo &info);
|
|
|
|
|
|
|
|
void add(StatByType &by_type, FileType file_type, int64 size);
|
|
|
|
|
|
|
|
static FileTypeStat get_nontemp_stat(const StatByType &by_type);
|
|
|
|
|
|
|
|
static td_api::object_ptr<td_api::storageStatisticsByChat> get_storage_statistics_by_chat_object(
|
|
|
|
DialogId dialog_id, const StatByType &stat_by_type_);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &sb, const FileStats &file_stats);
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileStats(bool need_all_files, bool split_by_owner_dialog_id)
|
|
|
|
: need_all_files_(need_all_files), split_by_owner_dialog_id_(split_by_owner_dialog_id) {
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-03-02 00:55:08 +01:00
|
|
|
void add_copy(const FullFileInfo &info);
|
2021-09-26 11:44:18 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void add(FullFileInfo &&info);
|
2021-09-26 11:44:18 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void apply_dialog_limit(int32 limit);
|
|
|
|
|
2021-09-26 18:38:27 +02:00
|
|
|
void apply_dialog_ids(const vector<DialogId> &dialog_ids);
|
|
|
|
|
2020-06-22 03:28:03 +02:00
|
|
|
tl_object_ptr<td_api::storageStatistics> get_storage_statistics_object() const;
|
2021-09-26 11:44:18 +02:00
|
|
|
|
|
|
|
vector<DialogId> get_dialog_ids() const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
FileTypeStat get_total_nontemp_stat() const;
|
|
|
|
|
2021-09-26 11:44:18 +02:00
|
|
|
vector<FullFileInfo> get_all_files();
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &sb, const FileStats &file_stats);
|
|
|
|
|
|
|
|
} // namespace td
|