Skip to content

Commit 158ea9f

Browse files
committed
Fix bounce action only triggering on n+1st bounce.
1 parent b6d60d9 commit 158ea9f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

queries.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,14 @@ camp AS (
798798
SELECT id FROM campaigns WHERE $3 != '' AND uuid = $3::UUID
799799
),
800800
bounce AS (
801-
-- Record the bounce if it the subscriber is not already blocklisted;
801+
-- Record the bounce if the subscriber is not already blocklisted;
802802
INSERT INTO bounces (subscriber_id, campaign_id, type, source, meta, created_at)
803803
SELECT (SELECT id FROM sub), (SELECT id FROM camp), $4, $5, $6, $7
804804
WHERE NOT EXISTS (SELECT 1 WHERE (SELECT status FROM sub) = 'blocklisted')
805805
),
806806
num AS (
807-
SELECT COUNT(*) AS num FROM bounces WHERE subscriber_id = (SELECT id FROM sub)
807+
-- Add a +1 to include the current insertion that is happening.
808+
SELECT COUNT(*) + 1 AS num FROM bounces WHERE subscriber_id = (SELECT id FROM sub)
808809
),
809810
-- block1 and block2 will run when $8 = 'blocklist' and the number of bounces exceed $8.
810811
block1 AS (

0 commit comments

Comments
 (0)