diff --git a/prisma/migrations/20240919210643_expire_boost_again/migration.sql b/prisma/migrations/20240919210643_expire_boost_again/migration.sql new file mode 100644 index 00000000..23660e4c --- /dev/null +++ b/prisma/migrations/20240919210643_expire_boost_again/migration.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE FUNCTION expire_boost_jobs() +RETURNS INTEGER +LANGUAGE plpgsql +AS $$ +DECLARE +BEGIN + INSERT INTO pgboss.job (name, data, retrylimit, retrybackoff, startafter, expirein) + SELECT 'expireBoost', jsonb_build_object('id', "Item".id), 21, true, now(), interval '1 days' + FROM "Item" + WHERE "Item".boost > 0 ON CONFLICT DO NOTHING; + return 0; +EXCEPTION WHEN OTHERS THEN + return 0; +END; +$$; + +SELECT expire_boost_jobs(); +DROP FUNCTION IF EXISTS expire_boost_jobs; \ No newline at end of file diff --git a/worker/expireBoost.js b/worker/expireBoost.js index 23b7f155..b538f84c 100644 --- a/worker/expireBoost.js +++ b/worker/expireBoost.js @@ -16,7 +16,7 @@ export async function expireBoost ({ data: { id }, models }) { AND "itemId" = ${Number(id)}::INTEGER ) UPDATE "Item" - SET boost = COALESCE(boost.cur_msats, 0), "oldBoost" = COALESCE(boost.old_msats, 0) + SET boost = COALESCE(boost.cur_msats, 0) / 1000, "oldBoost" = COALESCE(boost.old_msats, 0) / 1000 FROM boost WHERE "Item".id = ${Number(id)}::INTEGER` ],