file mgr db unit tests and fixes
This commit is contained in:
parent
1bbe5fbef4
commit
2493a16828
@ -33,8 +33,8 @@ namespace {
|
||||
[[nodiscard]] auto
|
||||
create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
const std::vector<rocksdb::ColumnFamilyDescriptor> &families,
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles,
|
||||
bool clear) -> std::unique_ptr<rocksdb::DB> {
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles, bool clear)
|
||||
-> std::unique_ptr<rocksdb::DB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto path = repertory::utils::path::combine(cfg.get_data_directory(), {name});
|
||||
@ -126,11 +126,26 @@ auto rdb_file_mgr_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
||||
db_->NewIterator(rocksdb::ReadOptions(), family));
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::get_next_upload() const -> std::optional<upload_entry> {}
|
||||
auto rdb_file_mgr_db::get_next_upload() const -> std::optional<upload_entry> {
|
||||
auto iter = create_iterator(upload_family_);
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
auto parts = utils::string::split(iter->key().ToString(), '|', false);
|
||||
parts.erase(parts.begin());
|
||||
|
||||
auto api_path = utils::string::join(parts, '|');
|
||||
|
||||
auto data = json::parse(iter->value().ToString());
|
||||
return upload_entry{
|
||||
api_path,
|
||||
data.at("date_time").get<std::uint64_t>(),
|
||||
data.at("source_path").get<std::string>(),
|
||||
};
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::get_resume_list() const -> std::vector<resume_entry> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
std::vector<resume_entry> ret;
|
||||
|
||||
auto iter = create_iterator(resume_family_);
|
||||
@ -150,9 +165,7 @@ auto rdb_file_mgr_db::get_resume_list() const -> std::vector<resume_entry> {
|
||||
|
||||
auto rdb_file_mgr_db::get_upload(const std::string &api_path) const
|
||||
-> std::optional<upload_entry> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
auto iter = create_iterator(upload_family_);
|
||||
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
auto parts = utils::string::split(iter->key().ToString(), '|', false);
|
||||
parts.erase(parts.begin());
|
||||
@ -194,7 +207,25 @@ auto rdb_file_mgr_db::remove_resume(const std::string &api_path) -> bool {
|
||||
});
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::remove_upload(const std::string &api_path) -> bool {}
|
||||
auto rdb_file_mgr_db::remove_upload(const std::string &api_path) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto iter = create_iterator(upload_family_);
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
auto parts = utils::string::split(iter->key().ToString(), '|', false);
|
||||
parts.erase(parts.begin());
|
||||
|
||||
if (api_path != utils::string::join(parts, '|')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return perform_action(function_name, []() -> rocksdb::Status {
|
||||
return db_->Delete(rocksdb::WriteOptions{}, iter->key());
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::remove_upload_active(const std::string &api_path)
|
||||
-> bool {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user