From d77d644e1510129f38136bb75a494adc319c6d08 Mon Sep 17 00:00:00 2001 From: keyan Date: Sun, 7 May 2023 16:20:18 -0500 Subject: [PATCH] lower noncritical job priority --- .../migration.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 prisma/migrations/20230507205613_update_job_priority/migration.sql diff --git a/prisma/migrations/20230507205613_update_job_priority/migration.sql b/prisma/migrations/20230507205613_update_job_priority/migration.sql new file mode 100644 index 00000000..4164e221 --- /dev/null +++ b/prisma/migrations/20230507205613_update_job_priority/migration.sql @@ -0,0 +1,33 @@ +-- lower user streak job priority +CREATE OR REPLACE FUNCTION user_streak_check() RETURNS TRIGGER AS $$ +DECLARE +BEGIN + INSERT INTO pgboss.job (name, data, priority) VALUES ('checkStreak', jsonb_build_object('id', NEW.id), -1); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +-- lower timestamp item job priority +CREATE OR REPLACE FUNCTION timestamp_item_on_insert() RETURNS TRIGGER AS $$ + BEGIN + IF NEW."subName" = 'jobs' THEN + RETURN NEW; + END IF; + INSERT INTO pgboss.job (name, data, startafter, priority) VALUES ('timestampItem', jsonb_build_object('id', NEW.id), now() + interval '10 minutes', -2); + RETURN NEW; + END; +$$ LANGUAGE plpgsql; + +-- we just need to index this item because it triggers a reindex of the parent due to comment count denormalization +-- job priority should be low because it's not critical it happens immediately +CREATE OR REPLACE FUNCTION index_item() RETURNS TRIGGER AS $$ + BEGIN + -- insert indexItem pgboss.job with id + INSERT INTO pgboss.job (name, data, priority) VALUES ('indexItem', jsonb_build_object('id', NEW.id), -100); + RETURN NEW; + END; +$$ LANGUAGE plpgsql; + +-- we can drop these triggers because item_acts denormalize into item and hit the item trigger +DROP TRIGGER IF EXISTS index_item_after_act ON "ItemAct"; +DROP FUNCTION index_item_after_act; \ No newline at end of file