f59ee5df17
* add subViewGroup function to create view to read sub stats from * add topSubs resolver to graphql query * add TOP_SUBS query fragment * add SUB_SORTS for top territory sorting * add custom cache policy for topSubs * add territories to top header select * add top territories page * add db views for sub stats * configure sub_stats views to refresh by worker * filter rows with empty subName * update msats_spent calculation to include all ItemAct in sub --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
33 lines
966 B
JavaScript
33 lines
966 B
JavaScript
import { PrismaClient } from '@prisma/client'
|
|
|
|
const viewPrefixes = ['reg_growth', 'spender_growth', 'item_growth', 'spending_growth',
|
|
'stackers_growth', 'stacking_growth', 'user_stats', 'sub_stats']
|
|
|
|
// this is intended to be run everyday after midnight CT
|
|
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 () {
|
|
// 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()
|
|
}
|
|
}
|