KeyValue pair add/update is being dealt properly now

This commit is contained in:
Taha Afzal authored and John Colvin committed 2021-12-29 13:18:48 -05:00
1 parent 7986bff968
commit cf1a5ada49
1 file changed
+15 -1
@@ -169,6 +169,20 @@ void AnalyticsServiceServer::clean_up(
// TODO
}
void _add_or_update(
persistence::IStore *store,
const std::string &ns,
const std::string &key,
const std::string &val) {
auto [exists, existing_val] = store->retrieve_one(ns, key);
if (exists) {
LOG(Gen, Info, "_add_or_update key:{} val:{} exists", key, existing_val);
store->update(ns, key, val);
} else {
store->insert(ns, key, val);
}
}
void AnalyticsServiceServer::set_exp_parameters(
const bts::api::analytics::ExpirationParameterEntryList &exp_params_args,
const api::Response<::bts::api::ResultMessage> &response) {
@@ -177,7 +191,7 @@ void AnalyticsServiceServer::set_exp_parameters(
std::string ns = me->exp_params_ns;
std::string key = std::to_string(1);
std::string value = utils::pb::to_string(exp_params);
// TODO: check to see if it adds or not
_add_or_update(me->exp_params_store.get(), ns, key, value);
me->exp_params_store->update(ns, key, value);
me->exp_params_publisher.add_or_update(exp_params);
me->exp_params_publisher.flush();