fix expire boost unit

This commit is contained in:
k00b 2024-09-19 16:10:04 -05:00
parent b4e143460b
commit ad9a65ce78
2 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -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`
],