Skip to content

Commit

Permalink
Fix bounce action only triggering on n+1st bounce.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Aug 22, 2021
1 parent b6d60d9 commit 158ea9f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,14 @@ camp AS (
SELECT id FROM campaigns WHERE $3 != '' AND uuid = $3::UUID
),
bounce AS (
-- Record the bounce if it the subscriber is not already blocklisted;
-- Record the bounce if the subscriber is not already blocklisted;
INSERT INTO bounces (subscriber_id, campaign_id, type, source, meta, created_at)
SELECT (SELECT id FROM sub), (SELECT id FROM camp), $4, $5, $6, $7
WHERE NOT EXISTS (SELECT 1 WHERE (SELECT status FROM sub) = 'blocklisted')
),
num AS (
SELECT COUNT(*) AS num FROM bounces WHERE subscriber_id = (SELECT id FROM sub)
-- Add a +1 to include the current insertion that is happening.
SELECT COUNT(*) + 1 AS num FROM bounces WHERE subscriber_id = (SELECT id FROM sub)
),
-- block1 and block2 will run when $8 = 'blocklist' and the number of bounces exceed $8.
block1 AS (
Expand Down

0 comments on commit 158ea9f

Please sign in to comment.