refactor cleanup
This commit is contained in:
@ -56,6 +56,10 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] virtual auto count() const -> std::uint64_t = 0;
|
[[nodiscard]] virtual auto count() const -> std::uint64_t = 0;
|
||||||
|
|
||||||
|
virtual void enumerate_api_path_list(
|
||||||
|
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||||
|
const stop_type &stop_requested) const = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const
|
std::string &api_path) const
|
||||||
-> api_error = 0;
|
-> api_error = 0;
|
||||||
|
@ -78,6 +78,10 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto count() const -> std::uint64_t override;
|
[[nodiscard]] auto count() const -> std::uint64_t override;
|
||||||
|
|
||||||
|
void enumerate_api_path_list(
|
||||||
|
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||||
|
const stop_type &stop_requested) const override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const
|
std::string &api_path) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
@ -53,6 +53,10 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto count() const -> std::uint64_t override;
|
[[nodiscard]] auto count() const -> std::uint64_t override;
|
||||||
|
|
||||||
|
void enumerate_api_path_list(
|
||||||
|
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||||
|
const stop_type &stop_requested) const override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const
|
std::string &api_path) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
@ -149,6 +149,54 @@ auto rdb_file_db::count() const -> std::uint64_t {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rdb_file_db::enumerate_api_path_list(
|
||||||
|
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||||
|
const stop_type &stop_requested) const {
|
||||||
|
std::vector<i_file_db::file_info> list;
|
||||||
|
{
|
||||||
|
auto iter = create_iterator(file_family_);
|
||||||
|
for (iter->SeekToFirst(); not stop_requested && iter->Valid();
|
||||||
|
iter->Next()) {
|
||||||
|
if (stop_requested) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto json_data = json::parse(iter->value().ToString());
|
||||||
|
list.emplace_back(i_file_db::file_info{
|
||||||
|
iter->key().ToString(),
|
||||||
|
false,
|
||||||
|
json_data.at("source_path").get<std::string>(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (list.size() < 100U) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(list);
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto iter = create_iterator(directory_family_);
|
||||||
|
for (iter->SeekToFirst(); not stop_requested && iter->Valid();
|
||||||
|
iter->Next()) {
|
||||||
|
list.emplace_back(i_file_db::file_info{
|
||||||
|
iter->key().ToString(),
|
||||||
|
true,
|
||||||
|
iter->value().ToString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (list.size() < 100U) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(list);
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto rdb_file_db::get_api_path(const std::string &source_path,
|
auto rdb_file_db::get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const -> api_error {
|
std::string &api_path) const -> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
@ -58,6 +58,12 @@ void rdb_meta_db::create_or_open(bool clear) {
|
|||||||
|
|
||||||
void rdb_meta_db::clear() { create_or_open(true); }
|
void rdb_meta_db::clear() { create_or_open(true); }
|
||||||
|
|
||||||
|
auto rdb_meta_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
||||||
|
-> std::shared_ptr<rocksdb::Iterator> {
|
||||||
|
return std::shared_ptr<rocksdb::Iterator>(
|
||||||
|
db_->NewIterator(rocksdb::ReadOptions{}, family));
|
||||||
|
}
|
||||||
|
|
||||||
void rdb_meta_db::enumerate_api_path_list(
|
void rdb_meta_db::enumerate_api_path_list(
|
||||||
std::function<void(const std::vector<std::string> &)> callback,
|
std::function<void(const std::vector<std::string> &)> callback,
|
||||||
const stop_type &stop_requested) const {
|
const stop_type &stop_requested) const {
|
||||||
@ -76,12 +82,6 @@ void rdb_meta_db::enumerate_api_path_list(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rdb_meta_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
|
||||||
-> std::shared_ptr<rocksdb::Iterator> {
|
|
||||||
return std::shared_ptr<rocksdb::Iterator>(
|
|
||||||
db_->NewIterator(rocksdb::ReadOptions{}, family));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rdb_meta_db::get_api_path(const std::string &source_path,
|
auto rdb_meta_db::get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const -> api_error {
|
std::string &api_path) const -> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
@ -133,6 +133,33 @@ auto sqlite_file_db::count() const -> std::uint64_t {
|
|||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sqlite_file_db::enumerate_api_path_list(
|
||||||
|
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||||
|
const stop_type &stop_requested) const {
|
||||||
|
std::vector<i_file_db::file_info> list;
|
||||||
|
|
||||||
|
auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
|
||||||
|
while (result.has_row() && not stop_requested) {
|
||||||
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
|
if (result.get_row(row) && row.has_value()) {
|
||||||
|
list.emplace_back(i_file_db::file_info{
|
||||||
|
.api_path = row->get_column("api_path").get_value<std::string>(),
|
||||||
|
.directory =
|
||||||
|
row->get_column("directory").get_value<std::int64_t>() == 1,
|
||||||
|
.source_path =
|
||||||
|
row->get_column("source_path").get_value<std::string>(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (list.size() < 100U) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(list);
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto sqlite_file_db::get_api_path(const std::string &source_path,
|
auto sqlite_file_db::get_api_path(const std::string &source_path,
|
||||||
std::string &api_path) const -> api_error {
|
std::string &api_path) const -> api_error {
|
||||||
auto result = utils::db::sqlite::db_select{*db_, file_table}
|
auto result = utils::db::sqlite::db_select{*db_, file_table}
|
||||||
@ -287,11 +314,7 @@ auto sqlite_file_db::get_item_list(const stop_type &stop_requested) const
|
|||||||
std::vector<i_file_db::file_info> ret;
|
std::vector<i_file_db::file_info> ret;
|
||||||
|
|
||||||
auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
|
auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
|
||||||
while (result.has_row()) {
|
while (result.has_row() && not stop_requested) {
|
||||||
if (stop_requested) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<utils::db::sqlite::db_result::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
ret.emplace_back(i_file_db::file_info{
|
ret.emplace_back(i_file_db::file_info{
|
||||||
@ -302,8 +325,6 @@ auto sqlite_file_db::get_item_list(const stop_type &stop_requested) const
|
|||||||
row->get_column("source_path").get_value<std::string>(),
|
row->get_column("source_path").get_value<std::string>(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
result.next_row();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -76,7 +76,6 @@ void sqlite_meta_db::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sqlite_meta_db::enumerate_api_path_list(
|
void sqlite_meta_db::enumerate_api_path_list(
|
||||||
bool directories,
|
|
||||||
std::function<void(const std::vector<std::string> &)> callback,
|
std::function<void(const std::vector<std::string> &)> callback,
|
||||||
const stop_type &stop_requested) const {
|
const stop_type &stop_requested) const {
|
||||||
auto result =
|
auto result =
|
||||||
@ -87,6 +86,7 @@ void sqlite_meta_db::enumerate_api_path_list(
|
|||||||
std::optional<utils::db::sqlite::db_result::row> row;
|
std::optional<utils::db::sqlite::db_result::row> row;
|
||||||
if (result.get_row(row) && row.has_value()) {
|
if (result.get_row(row) && row.has_value()) {
|
||||||
list.push_back(row->get_column("api_path").get_value<std::string>());
|
list.push_back(row->get_column("api_path").get_value<std::string>());
|
||||||
|
|
||||||
if (list.size() < 100U) {
|
if (list.size() < 100U) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -806,9 +806,10 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
|
void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
|
||||||
|
db_->enumerate_api_path_list(
|
||||||
|
[this, &stop_requested](auto &&list) {
|
||||||
std::vector<i_file_db::file_info> removed_list{};
|
std::vector<i_file_db::file_info> removed_list{};
|
||||||
|
for (const auto &item : list) {
|
||||||
for (const auto &item : db_->get_item_list(stop_requested)) {
|
|
||||||
if (stop_requested) {
|
if (stop_requested) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -831,9 +832,11 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_system::instance().raise<file_removed_externally>(item.api_path,
|
event_system::instance().raise<file_removed_externally>(
|
||||||
item.source_path);
|
item.api_path, item.source_path);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stop_requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
||||||
|
Reference in New Issue
Block a user