use greedy connection from view refreshes
This commit is contained in:
parent
5086c2036d
commit
6179d14a68
@ -1,16 +1,32 @@
|
|||||||
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
|
||||||
const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth',
|
const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth',
|
||||||
'stackers_growth', 'stacking_growth', 'user_stats']
|
'stackers_growth', 'stacking_growth', 'user_stats']
|
||||||
|
|
||||||
// this is intended to be run everyday after midnight CT
|
// this is intended to be run everyday after midnight CT
|
||||||
export async function views ({ data: { period } = { period: 'days' }, models }) {
|
export async function views ({ data: { period } = { period: 'days' } }) {
|
||||||
|
// grab a greedy connection
|
||||||
|
const models = new PrismaClient()
|
||||||
|
|
||||||
|
try {
|
||||||
for (const view of viewPrefixes) {
|
for (const view of viewPrefixes) {
|
||||||
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`)
|
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
await models.$disconnect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this should be run regularly ... like, every 5 minutes
|
// this should be run regularly ... like, every 5 minutes
|
||||||
export async function rankViews ({ models }) {
|
export async function rankViews () {
|
||||||
|
// grab a greedy connection
|
||||||
|
const models = new PrismaClient()
|
||||||
|
|
||||||
|
try {
|
||||||
for (const view of ['zap_rank_personal_view']) {
|
for (const view of ['zap_rank_personal_view']) {
|
||||||
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
|
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
await models.$disconnect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user