From 620e89d528f86bf9bb5be2aaffff5ae4321278c5 Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Thu, 3 Sep 2026 20:18:43 -0700 Subject: [PATCH] feat: exclude action and wait steps from the workspace daily email limit by joining the step kind, since they stamp sent_at for routing without sending mail --- internal/repository/pg_campaign_progress.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/repository/pg_campaign_progress.go b/internal/repository/pg_campaign_progress.go index 17e45e90..697d5812 100644 --- a/internal/repository/pg_campaign_progress.go +++ b/internal/repository/pg_campaign_progress.go @@ -819,12 +819,15 @@ func (r *campaignProgressRepository) CheckContactHasReplied(ctx context.Context, return hasReplied, err } -// CountEmailsSentTodayByOrganization returns how many campaign emails were sent today by an organization. +// CountEmailsSentTodayByOrganization returns how many campaign emails were sent +// today by an organization. Action and wait steps stamp sent_at too, for +// routing, but send nothing, so only email steps count. func (r *campaignProgressRepository) CountEmailsSentTodayByOrganization(ctx context.Context, organizationID uuid.UUID) (int, error) { query := ` SELECT COUNT(*) FROM campaign_contact_progress ccp JOIN campaigns c ON c.id = ccp.campaign_id + JOIN sequences s ON s.id = ccp.sequence_id AND s.kind = 'email' WHERE c.organization_id = $1 AND ccp.sent_at IS NOT NULL AND DATE(ccp.sent_at) = CURRENT_DATE