Make UserSubscription as shared_ptr in Subscription
Currently UserSubscription are used as value in Subscription. This
causes the copy of the object between subscriptionsMap and
subscriptionConfigMap when doing PATCH.
Using a shared_ptr for UserSubscription avoids the memory copy of it.
Tested:
- Using Redfish Event Listener, test subscriptions and eventing.
- Redfish Service Validator passes
Change-Id: I5821b72f28ba737a5c9b75288d377766c84c6a6a
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index ef2adf3..afcdb14 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -172,11 +172,11 @@
BMCWEB_LOG_DEBUG("Restored subscription: {} {}",
newSub->id, newSub->customText);
- boost::container::flat_map<
- std::string, UserSubscription>& configMap =
- EventServiceStore::getInstance()
- .subscriptionsConfigMap;
- configMap.emplace(newSub->id, *newSub);
+ EventServiceStore::getInstance()
+ .subscriptionsConfigMap.emplace(
+ newSub->id,
+ std::make_shared<UserSubscription>(
+ std::move(*newSub)));
}
}
else
@@ -299,7 +299,11 @@
for (const auto& it :
EventServiceStore::getInstance().subscriptionsConfigMap)
{
- const UserSubscription& subValue = it.second;
+ if (it.second == nullptr)
+ {
+ continue;
+ }
+ const UserSubscription& subValue = *it.second;
if (subValue.subscriptionType == "SSE")
{
BMCWEB_LOG_DEBUG("The subscription type is SSE, so skipping.");