stacker.news/worker/views.js

30 lines
917 B
JavaScript
Raw Normal View History

// this is intended to be run everyday after midnight CT
2023-05-18 23:41:56 +00:00
function views ({ models }) {
return async function () {
console.log('refreshing stats views')
2023-05-18 23:41:56 +00:00
for (const view of ['reg_growth_days', 'spender_growth_days', 'item_growth_days',
'spending_growth_days', 'stackers_growth_days', 'stacking_growth_days',
'user_stats_days']) {
2023-07-26 16:01:31 +00:00
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
2023-05-18 23:41:56 +00:00
}
console.log('done refreshing stats views')
2023-05-18 23:41:56 +00:00
}
}
2023-05-23 14:21:04 +00:00
// this should be run regularly ... like, every 1-5 minutes
function rankViews ({ models }) {
return async function () {
console.log('refreshing rank views')
for (const view of ['sat_rank_wwm_view', 'sat_rank_tender_view']) {
2023-07-26 16:01:31 +00:00
await models.$queryRawUnsafe(`REFRESH MATERIALIZED VIEW CONCURRENTLY ${view}`)
2023-05-23 14:21:04 +00:00
}
console.log('done refreshing rank views')
}
}
module.exports = { views, rankViews }