From 628f755afd33f7d31ca34d8a585e0ade5935d0e9 Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 21 Dec 2023 17:48:16 -0600 Subject: [PATCH] give rewards its own db connection pool --- worker/earn.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/worker/earn.js b/worker/earn.js index d14f3da4..c6b2df5f 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -2,17 +2,20 @@ import serialize from '../api/resolvers/serial.js' import { sendUserNotification } from '../api/webPush/index.js' import { ANON_USER_ID, SN_USER_IDS } from '../lib/constants.js' import { msatsToSats, numWithUnits } from '../lib/format.js' +import { PrismaClient } from '@prisma/client' const ITEM_EACH_REWARD = 4.0 const UPVOTE_EACH_REWARD = 4.0 const TOP_PERCENTILE = 33 const TOTAL_UPPER_BOUND_MSATS = 1000000000 -export async function earn ({ name, models }) { +export async function earn ({ name }) { // rewards are calculated sitewide still // however for user gen subs currently only 50% of their fees go to rewards // the other 50% goes to the founder of the sub + const models = new PrismaClient() + // compute how much sn earned today const [{ sum: sumDecimal }] = await models.$queryRaw` SELECT coalesce(sum(msats), 0) as sum