mirror of
https://github.com/block/buzz.git
synced 2026-10-29 21:41:33 +00:00
25 lines
954 B
PL/PgSQL
25 lines
954 B
PL/PgSQL
-- Dogfood push is deliberately message-only. Replace the trigger allowlist
|
|
-- additively so already-applied 0018/0023 migrations remain checksum-stable.
|
|
CREATE OR REPLACE FUNCTION enqueue_push_match_job() RETURNS trigger
|
|
LANGUAGE plpgsql AS $$
|
|
BEGIN
|
|
-- Keep this allowlist identical to the relay's validated NIP-PL descriptor.
|
|
IF NEW.kind IN (9, 40002, 45001, 45003) THEN
|
|
PERFORM pg_advisory_xact_lock_shared(
|
|
hashtextextended('buzz_push_gate:' || NEW.community_id::text, 0));
|
|
IF EXISTS (
|
|
SELECT 1 FROM push_leases
|
|
WHERE community_id = NEW.community_id
|
|
AND active
|
|
AND endpoint_enabled
|
|
AND expires_at > EXTRACT(EPOCH FROM now())::bigint
|
|
) THEN
|
|
INSERT INTO push_match_queue (community_id, event_id)
|
|
VALUES (NEW.community_id, NEW.id)
|
|
ON CONFLICT DO NOTHING;
|
|
END IF;
|
|
END IF;
|
|
RETURN NEW;
|
|
END
|
|
$$;
|