Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

fix(database): count distinct replies for the per-recipient limit

spacesdrive049dcb241af5
diff --git a/supabase/migrations/20261016100800_create_reserve_automation_send_function.sql b/supabase/migrations/20261016100800_create_reserve_automation_send_function.sql
index b66451d..591d930 100644
--- a/supabase/migrations/20261016100800_create_reserve_automation_send_function.sql
+++ b/supabase/migrations/20261016100800_create_reserve_automation_send_function.sql
@@ -39,10 +39,12 @@ begin
return;
end if;
- -- a person who comments again and again gets a few replies a day, never a stream of them
+ -- a person who comments again and again gets a few replies a day, never a stream of them; retries of this
+ -- comment are one reply, so only other comments count
if job.from_id is not null and (
- select count(*) from public.automation_attempts t
- where t.account_id = job.account_id and t.recipient_id = job.from_id and t.started_at > now() - interval '1 day'
+ select count(distinct t.automation_comment_id) from public.automation_attempts t
+ where t.account_id = job.account_id and t.recipient_id = job.from_id
+ and t.started_at > now() - interval '1 day' and t.automation_comment_id <> job.id
) >= p_recipient_limit then
return query select 'recipient_limit'::text, null::timestamptz;
return;