From 4939404ef1cb4464e9203179b22ed9802161b6c7 Mon Sep 17 00:00:00 2001 From: Aashish Dhakal <85501584+dhakalaashish@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:12:07 +0545 Subject: [PATCH] Fix Notification Creation Logic Some siteAlerts were still unprocessed. This was because these siteAlerts do not have any associated enabled-alertMethod, so they were not considered by the SQL query. To address these unprocessed siteAlerts, I added another SQL to process all remaining unprocessed siteAlerts. --- .../src/Services/Notifications/CreateNotifications.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/server/src/Services/Notifications/CreateNotifications.ts b/apps/server/src/Services/Notifications/CreateNotifications.ts index fe37041ba..09d0bdd07 100644 --- a/apps/server/src/Services/Notifications/CreateNotifications.ts +++ b/apps/server/src/Services/Notifications/CreateNotifications.ts @@ -71,6 +71,13 @@ const createNotifications = async () => { totalSiteAlertProcessed += siteAlertProcessed if(siteAlertProcessed === 0){ + // All notifications have been created, however, there might be some siteAlerts that are still unprocessed + // This is because these siteAlerts do not have any associated enabled-alertMethod, so they were not considered by the SQL above + // To address these unprocessed siteAlerts, update isProcessed for all remaining unprocessed siteAlerts to true + const updateSiteAlertIsProcessedToTrue = Prisma.sql` + UPDATE "SiteAlert" SET "isProcessed" = true WHERE "isProcessed" = false AND "deletedAt" IS NULL`; + await prisma.$executeRaw(updateSiteAlertIsProcessedToTrue) + // Exit the while loop moreAlertsToProcess = false; // No more alerts to process, exit the loop }else { await new Promise(resolve => setTimeout(resolve, 200)); // Delay of 1/5 second