From eea71832ec3aa709d3cbf2d72bdb51dc3fae01f6 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Sat, 17 Oct 2026 05:43:20 +0200 Subject: [PATCH] feat: count campaign progress emails_sent through the existing sequences join and return the restore context error when ANALYZE is cancelled --- cmd/warmblyctl/backup.go | 3 +++ internal/repository/pg_campaign_progress.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/warmblyctl/backup.go b/cmd/warmblyctl/backup.go index 5f9388244..05159db96 100644 --- a/cmd/warmblyctl/backup.go +++ b/cmd/warmblyctl/backup.go @@ -306,6 +306,9 @@ func runRestore(ctx context.Context, args []string) error { } fmt.Println(" database restored") if err := analyzeDatabase(ctx, dsn); err != nil { + if ctx.Err() != nil { + return ctx.Err() + } warn("the database restored, but ANALYZE did not finish, so queries plan without statistics until autovacuum gathers them. Run ANALYZE by hand:\n%s", err) } else { fmt.Println(" statistics analyzed") diff --git a/internal/repository/pg_campaign_progress.go b/internal/repository/pg_campaign_progress.go index 701332b1a..c7a643915 100644 --- a/internal/repository/pg_campaign_progress.go +++ b/internal/repository/pg_campaign_progress.go @@ -1148,7 +1148,7 @@ func (r *campaignProgressRepository) GetCampaignProgress(ctx context.Context, ca SELECT (SELECT COUNT(DISTINCT contact_id) FROM campaign_leads WHERE campaign_id = $1) AS total_contacts, (SELECT COUNT(*) FROM sequences WHERE campaign_id = $1 AND kind = 'email') AS total_sequences, - COUNT(*) FILTER (WHERE ccp.sent_at IS NOT NULL AND ` + progressIsEmailStep("ccp") + `) AS emails_sent, + COUNT(*) FILTER (WHERE ccp.sent_at IS NOT NULL AND es.id IS NOT NULL) AS emails_sent, COUNT(*) FILTER (WHERE ccp.opened_at IS NOT NULL AND NOT ccp.opened_machine) AS emails_opened, COUNT(*) FILTER (WHERE ccp.clicked_at IS NOT NULL) AS emails_clicked, COUNT(*) FILTER (WHERE ccp.replied_at IS NOT NULL) AS emails_replied,