Fix notification overwrite caused by stale notification cache

Changes:
- Retrieved the notifications map before creating a new notification in sendNotification().
- Ensured the notification cache is refreshed before generating a notification ID.
- Prevented newly created notifications from overwriting notifications added by other operations prior to save.

Fixes #2079
This commit is contained in:
2026-06-17 14:07:38 +05:30
parent 78e6ae2fec
commit b011f600cf
3 changed files with 3 additions and 3 deletions
@@ -270,6 +270,7 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
{
return;
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
Notification* notification = Factory::getObject<Notification>(
user->getId(),
title,
@@ -279,7 +280,6 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
{
throw std::runtime_error("Failed to create notification");
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
m_dataStore.saveNotifications();
EventManager::sendNotificationAvailableEvent(user->getId());
@@ -98,6 +98,7 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t
{
return;
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
Notification* notification = Factory::getObject<Notification>(
user->getId(),
title,
@@ -107,7 +108,6 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t
{
throw std::runtime_error("Failed to create notification");
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
m_dataStore.saveNotifications();
EventManager::sendNotificationAvailableEvent(user->getId());
@@ -188,6 +188,7 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t
{
return;
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
Notification* notification = Factory::getObject<Notification>(
user->getId(),
title,
@@ -197,7 +198,6 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t
{
throw std::runtime_error("Failed to create notification");
}
auto& trackedNotificationsMap = m_dataStore.getNotifications();
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
m_dataStore.saveNotifications();
EventManager::sendNotificationAvailableEvent(user->getId());