From 55b943fc45c7d9362276a332426a15d33ea69303 Mon Sep 17 00:00:00 2001 From: mherrera Date: Tue, 27 Jan 2026 15:11:28 -0300 Subject: [PATCH 1/6] refactor: use new table --- .../Infrastructure/CampaignRepository.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs index a0bdd89..0bf3ed6 100644 --- a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs @@ -45,11 +45,11 @@ FROM dbo.usertimezone timezone DATEADD(MINUTE, @timezone, C.[UTCSentDate]) AS DATE ) AS [Date] - ,COALESCE(C.[AmountSentSubscribers], C.[AmountSubscribersToSend], 0) AS [Sent] - ,ISNULL(C.[DistinctOpenedMailCount],0) [Opens] - ,ISNULL(C.[DistinctClickCount],0) [Clicks] - ,ISNULL(C.[HardBouncedMailCount],0) [Hard] - ,ISNULL (C.[SoftBouncedMailCount],0) [Soft] + ,COALESCE(CS.[AmountSentSubscribers], CS.[AmountSubscribersToSend], 0) AS [Sent] + ,ISNULL(CS.[DistinctOpenedMailCount],0) [Opens] + ,ISNULL(CS.[DistinctClickCount],0) [Clicks] + ,ISNULL(CS.[HardBouncedMailCount],0) [Hard] + ,ISNULL (CS.[SoftBouncedMailCount],0) [Soft] ,(CASE C.[Status] WHEN 9 THEN ISNULL(C.[UnsubscriptionsCount],0) @@ -57,6 +57,7 @@ ELSE 0 END) [Unsubscribes] ,0 [Spam] FROM [dbo].[Campaign] C WITH (NOLOCK) + LEFT JOIN dbo.CampaignStats CS ON CS.IdCampaign = C.IdCampaign JOIN [dbo].[User] U WITH (NOLOCK) ON C.[IdUser] = U.[IdUser] WHERE From c7eb868e0c8a8855a013ffeab45e3f67612d3bb2 Mon Sep 17 00:00:00 2001 From: mherrera Date: Tue, 27 Jan 2026 15:18:44 -0300 Subject: [PATCH 2/6] refactor: use new table for stats --- Doppler.ReportingApi/Infrastructure/SummaryRepository.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs index 08d4401..25816d8 100644 --- a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs @@ -29,13 +29,15 @@ public async Task GetCampaignsSummaryByUserAsync(string userNa CAST(NULLIF((ISNULL(T.DistinctOpenedMailCount, 0) + ISNULL(T.UnopenedMailCount, 0)), 0) AS FLOAT) * 100 AS ClickThroughRate FROM ( SELECT - SUM(Campaign.AmountSentSubscribers) AS TotalSentEmails, - SUM(Campaign.DistinctOpenedMailCount) AS DistinctOpenedMailCount, + SUM(CS.AmountSentSubscribers) AS TotalSentEmails, + SUM(CS.DistinctOpenedMailCount) AS DistinctOpenedMailCount, - SUM(Campaign.UnopenedMailCount) AS UnopenedMailCount, + SUM(CS.UnopenedMailCount) AS UnopenedMailCount, SUM(LinkInfo.UniqueClickCount) AS UniqueClickCount FROM [user] INNER JOIN Campaign WITH (NOLOCK) on [user].iduser = Campaign.IdUser + LEFT JOIN CampaignStats CS ON CS.IdCampaign = Campaign.IdCampaign + OUTER APPLY ( SELECT COUNT(DISTINCT LT.IdSubscriber) AS UniqueClickCount FROM Link L WITH (NOLOCK) From 275848a5291a8321de848f28631c4ea20a9aa48f Mon Sep 17 00:00:00 2001 From: mherrera Date: Wed, 18 Mar 2026 14:55:38 -0300 Subject: [PATCH 3/6] refactor: Use UnsubscriptionCount from Stat table --- Doppler.ReportingApi/Infrastructure/CampaignRepository.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs index 0bf3ed6..4ad3554 100644 --- a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs @@ -50,11 +50,7 @@ AS DATE ,ISNULL(CS.[DistinctClickCount],0) [Clicks] ,ISNULL(CS.[HardBouncedMailCount],0) [Hard] ,ISNULL (CS.[SoftBouncedMailCount],0) [Soft] - ,(CASE C.[Status] - WHEN 9 - THEN ISNULL(C.[UnsubscriptionsCount],0) - ELSE 0 - END) [Unsubscribes] + ,ISNULL(CS.[UnsubscriptionsCount],0) [Unsubscribes] ,0 [Spam] FROM [dbo].[Campaign] C WITH (NOLOCK) LEFT JOIN dbo.CampaignStats CS ON CS.IdCampaign = C.IdCampaign From 32b189ab1f60c55bc0d53a90dfbc40d5b9f4497a Mon Sep 17 00:00:00 2001 From: mherrera Date: Wed, 15 Apr 2026 16:51:26 -0300 Subject: [PATCH 4/6] chore: untibify query --- Doppler.ReportingApi/Infrastructure/CampaignRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs index 4ad3554..7f09513 100644 --- a/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/CampaignRepository.cs @@ -53,7 +53,7 @@ AS DATE ,ISNULL(CS.[UnsubscriptionsCount],0) [Unsubscribes] ,0 [Spam] FROM [dbo].[Campaign] C WITH (NOLOCK) - LEFT JOIN dbo.CampaignStats CS ON CS.IdCampaign = C.IdCampaign + LEFT JOIN dbo.CampaignStats CS ON CS.IdCampaign = C.IdCampaign JOIN [dbo].[User] U WITH (NOLOCK) ON C.[IdUser] = U.[IdUser] WHERE From f84c67d61477886c0bc0d1f21b52dafb9fd47fe9 Mon Sep 17 00:00:00 2001 From: mherrera Date: Wed, 15 Apr 2026 17:04:53 -0300 Subject: [PATCH 5/6] fix: untibify query --- Doppler.ReportingApi/Infrastructure/SummaryRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs index 25816d8..e29718e 100644 --- a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs @@ -36,8 +36,8 @@ public async Task GetCampaignsSummaryByUserAsync(string userNa SUM(LinkInfo.UniqueClickCount) AS UniqueClickCount FROM [user] INNER JOIN Campaign WITH (NOLOCK) on [user].iduser = Campaign.IdUser - LEFT JOIN CampaignStats CS ON CS.IdCampaign = Campaign.IdCampaign - + LEFT JOIN CampaignStats CS ON CS.IdCampaign = Campaign.IdCampaign + OUTER APPLY ( SELECT COUNT(DISTINCT LT.IdSubscriber) AS UniqueClickCount FROM Link L WITH (NOLOCK) From 6bb8d5f34f906149c7ffa33f2191ab0dffeb58d5 Mon Sep 17 00:00:00 2001 From: mherrera Date: Wed, 15 Apr 2026 17:09:11 -0300 Subject: [PATCH 6/6] fix: fix unexpected trailing whitespace error --- Doppler.ReportingApi/Infrastructure/SummaryRepository.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs index e29718e..cd4955a 100644 --- a/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs +++ b/Doppler.ReportingApi/Infrastructure/SummaryRepository.cs @@ -37,7 +37,6 @@ public async Task GetCampaignsSummaryByUserAsync(string userNa FROM [user] INNER JOIN Campaign WITH (NOLOCK) on [user].iduser = Campaign.IdUser LEFT JOIN CampaignStats CS ON CS.IdCampaign = Campaign.IdCampaign - OUTER APPLY ( SELECT COUNT(DISTINCT LT.IdSubscriber) AS UniqueClickCount FROM Link L WITH (NOLOCK)