From b011f600cff399d3dc12e69739d64d71e0e45701 Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Wed, 17 Jun 2026 14:07:38 +0530 Subject: [PATCH] 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 --- .../services/InventoryManagementService.cpp | 2 +- .../services/PaymentManagementService.cpp | 2 +- .../services/ServiceManagementService.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp index a007ac1..f906431 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp @@ -270,6 +270,7 @@ void InventoryManagementService::sendNotification(User* user, const std::string& { return; } + auto& trackedNotificationsMap = m_dataStore.getNotifications(); Notification* notification = Factory::getObject( 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()); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp index 09bf1da..dad4421 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp @@ -98,6 +98,7 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t { return; } + auto& trackedNotificationsMap = m_dataStore.getNotifications(); Notification* notification = Factory::getObject( 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()); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index cf438d0..e703453 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -188,6 +188,7 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t { return; } + auto& trackedNotificationsMap = m_dataStore.getNotifications(); Notification* notification = Factory::getObject( 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());