feat: count campaign progress emails_sent through the existing sequences join and return the restore context error when ANALYZE is cancelled

This commit is contained in:
Matthew Meszaros
2026-10-17 05:43:20 +02:00
parent ae9eca5c7e
commit eea71832ec
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -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")
+1 -1
View File
@@ -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,