diff --git a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp index db992961..a3b2565c 100644 --- a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp @@ -490,50 +490,7 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data, json_data.erase(META_PINNED); json_data.erase(META_SIZE); - const auto do_transaction = - [&](rocksdb::Transaction *txn) -> rocksdb::Status { - if (should_del_source) { - auto res = txn->Delete(source_family_, orig_source_path); - if (status != nullptr) { - *status = res; - } - - if (not res.ok()) { - return res; - } - } - - auto res = - txn->Put(pinned_family_, api_path, utils::string::from_bool(pinned)); - if (status != nullptr) { - *status = res; - } - - if (not res.ok()) { - return res; - } - - res = txn->Put(size_family_, api_path, std::to_string(size)); - if (status != nullptr) { - *status = res; - } - - if (not res.ok()) { - return res; - } - - if (not source_path.empty()) { - res = txn->Put(source_family_, source_path, api_path); - if (status != nullptr) { - *status = res; - } - - if (not res.ok()) { - return res; - } - } - - res = txn->Put(default_family_, api_path, json_data.dump()); + const auto set_status = [&status](rocksdb::Status res) -> rocksdb::Status { if (status != nullptr) { *status = res; } @@ -541,15 +498,41 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data, return res; }; + const auto do_transaction = + [&](rocksdb::Transaction *txn) -> rocksdb::Status { + if (should_del_source) { + auto res = set_status(txn->Delete(source_family_, orig_source_path)); + if (not res.ok()) { + return res; + } + } + + auto res = set_status( + txn->Put(pinned_family_, api_path, utils::string::from_bool(pinned))); + if (not res.ok()) { + return res; + } + + res = set_status(txn->Put(size_family_, api_path, std::to_string(size))); + if (not res.ok()) { + return res; + } + + if (not source_path.empty()) { + res = set_status(txn->Put(source_family_, source_path, api_path)); + if (not res.ok()) { + return res; + } + } + + return set_status(txn->Put(default_family_, api_path, json_data.dump())); + }; + if (base_txn == nullptr) { return perform_action(function_name, do_transaction); } - auto res = do_transaction(base_txn); - if (status != nullptr) { - *status = res; - } - + auto res = set_status(do_transaction(base_txn)); if (res.ok()) { return api_error::success; }