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:
+1
-1
@@ -270,6 +270,7 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
||||||
Notification* notification = Factory::getObject<Notification>(
|
Notification* notification = Factory::getObject<Notification>(
|
||||||
user->getId(),
|
user->getId(),
|
||||||
title,
|
title,
|
||||||
@@ -279,7 +280,6 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to create notification");
|
throw std::runtime_error("Failed to create notification");
|
||||||
}
|
}
|
||||||
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
|
||||||
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
||||||
m_dataStore.saveNotifications();
|
m_dataStore.saveNotifications();
|
||||||
EventManager::sendNotificationAvailableEvent(user->getId());
|
EventManager::sendNotificationAvailableEvent(user->getId());
|
||||||
|
|||||||
+1
-1
@@ -98,6 +98,7 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
||||||
Notification* notification = Factory::getObject<Notification>(
|
Notification* notification = Factory::getObject<Notification>(
|
||||||
user->getId(),
|
user->getId(),
|
||||||
title,
|
title,
|
||||||
@@ -107,7 +108,6 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to create notification");
|
throw std::runtime_error("Failed to create notification");
|
||||||
}
|
}
|
||||||
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
|
||||||
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
||||||
m_dataStore.saveNotifications();
|
m_dataStore.saveNotifications();
|
||||||
EventManager::sendNotificationAvailableEvent(user->getId());
|
EventManager::sendNotificationAvailableEvent(user->getId());
|
||||||
|
|||||||
+1
-1
@@ -188,6 +188,7 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
||||||
Notification* notification = Factory::getObject<Notification>(
|
Notification* notification = Factory::getObject<Notification>(
|
||||||
user->getId(),
|
user->getId(),
|
||||||
title,
|
title,
|
||||||
@@ -197,7 +198,6 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to create notification");
|
throw std::runtime_error("Failed to create notification");
|
||||||
}
|
}
|
||||||
auto& trackedNotificationsMap = m_dataStore.getNotifications();
|
|
||||||
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
trackedNotificationsMap.insert(notification->getId(), util::createNewRecord(notification));
|
||||||
m_dataStore.saveNotifications();
|
m_dataStore.saveNotifications();
|
||||||
EventManager::sendNotificationAvailableEvent(user->getId());
|
EventManager::sendNotificationAvailableEvent(user->getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user