fix: Emplace MDConsumerHandle instead of copy assign

This commit is contained in:
John Colvin committed 2024-10-30 19:35:05 +00:00
1 parent 5543725ee2
commit 132201d2cf
2 files changed
+37 -12

No files matched your search

@@ -118,11 +118,24 @@ class HandleIndex {
LOG(md, Diag,
"PositionService::HandleIndex::on_security security:{}",
bts::securities::descriptor(*sec));
if (_consumer->id() == id) {
index.lock([handle](auto &index) {
index[SecurityKey(handle.key())] = handle;
});
if (_consumer->id() != id) {
return;
}
index.lock(
[handle](std::unordered_map<SecurityKey, MDConsumerHandle>
&index) {
SecurityKey sec_key{handle.key()};
if (index.find(sec_key) != index.end()) {
return;
}
auto [_, is_new] =
index.try_emplace(sec_key, std::move(handle));
if (is_new) {
LOG(md, Info,
"MBOServiceServer added synthetic security: {}",
*sec_key);
}
});
});
}
}
+20 -8
View File
@@ -59,14 +59,26 @@ class HandleIndex {
}
// Subscribe to on_security
auto id = _consumer->id();
_consumer->on_security(
[this, id](const SecurityPtr &, MDConsumerHandle handle) {
if (_consumer->id() == id) {
index.lock([handle](auto &index) {
index[SecurityKey(handle.key())] = handle;
});
}
});
_consumer->on_security([this, id](
const SecurityPtr &,
MDConsumerHandle handle) {
if (_consumer->id() != id) {
return;
}
index.lock(
[handle](
std::unordered_map<SecurityKey, MDConsumerHandle> &index) {
SecurityKey sec_key{handle.key()};
if (index.find(sec_key) != index.end()) {
return;
}
auto [_, is_new] =
index.try_emplace(sec_key, std::move(handle));
if (is_new) {
LOG(md, Info, "MBOServiceServer added security: {}", *sec_key);
}
});
});
}
}
};