2024-07-16 18:41:44 +00:00
|
|
|
import createPrisma from '@/lib/create-prisma.js'
|
2024-01-26 00:09:33 +00:00
|
|
|
|
2024-01-19 21:19:26 +00:00
|
|
|
const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth',
|
2024-02-14 20:27:00 +00:00
|
|
|
'stackers_growth', 'stacking_growth', 'user_stats', 'sub_stats']
|
2024-01-19 21:19:26 +00:00
|
|
|
|
2023-05-19 22:33:54 +00:00
|
|
|
// this is intended to be run everyday after midnight CT
|
2024-01-26 00:09:33 +00:00
|
|
|
export async function views ({ data: { period } = { period: 'days' } }) {
|
|
|
|
// grab a greedy connection
|
2024-07-16 18:41:44 +00:00
|
|
|
const models = createPrisma({ connectionParams: { connection_limit: 1 } })
|
2024-01-26 00:09:33 +00:00
|
|
|
|
|
|
|
try {
|
2024-03-01 16:28:55 +00:00
|
|
|
// these views are bespoke so we can't use the loop
|
|
|
|
if (period === 'days') {
|
|
|
|
await models.$queryRawUnsafe('REFRESH MATERIALIZED VIEW CONCURRENTLY user_values_days')
|
|
|
|
await models.$queryRawUnsafe('REFRESH MATERIALIZED VIEW CONCURRENTLY rewards_days')
|
|
|
|
}
|
|
|
|
if (period === 'hours') {
|
|
|
|
await models.$queryRawUnsafe('REFRESH MATERIALIZED VIEW CONCURRENTLY user_values_today')
|
|
|
|
await models.$queryRawUnsafe('REFRESH MATERIALIZED VIEW CONCURRENTLY rewards_today')
|
|
|
|
}
|
2024-01-26 00:09:33 +00:00
|
|
|
for (const view of viewPrefixes) {
|
|
|
|
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}_${period}`)
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
await models.$disconnect()
|
2023-05-18 23:41:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 15:46:59 +00:00
|
|
|
// this should be run regularly ... like, every 5 minutes
|
2024-01-26 00:09:33 +00:00
|
|
|
export async function rankViews () {
|
|
|
|
// grab a greedy connection
|
2024-07-16 18:41:44 +00:00
|
|
|
const models = createPrisma({ connectionParams: { connection_limit: 1 } })
|
2024-01-26 00:09:33 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
for (const view of ['zap_rank_personal_view']) {
|
|
|
|
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
await models.$disconnect()
|
2023-05-23 14:21:04 +00:00
|
|
|
}
|
|
|
|
}
|