From 6179d14a687468bab686b768cf4d56a5fcb6d2a5 Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 25 Jan 2024 18:09:33 -0600 Subject: [PATCH] use greedy connection from view refreshes --- worker/views.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/worker/views.js b/worker/views.js index 1373aa3e..7ea8be37 100644 --- a/worker/views.js +++ b/worker/views.js @@ -1,16 +1,32 @@ +import { PrismaClient } from '@prisma/client' + const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth', 'stackers_growth', 'stacking_growth', 'user_stats'] // this is intended to be run everyday after midnight CT -export async function views ({ data: { period } = { period: 'days' }, models }) { - for (const view of viewPrefixes) { - await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`) +export async function views ({ data: { period } = { period: 'days' } }) { + // grab a greedy connection + const models = new PrismaClient() + + try { + for (const view of viewPrefixes) { + await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`) + } + } finally { + await models.$disconnect() } } // this should be run regularly ... like, every 5 minutes -export async function rankViews ({ models }) { - for (const view of ['zap_rank_personal_view']) { - await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`) +export async function rankViews () { + // grab a greedy connection + const models = new PrismaClient() + + try { + for (const view of ['zap_rank_personal_view']) { + await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`) + } + } finally { + await models.$disconnect() } }