@@ -3,6 +3,10 @@ const dotenv = require('dotenv');
33const logCaching = process . env . LOG_CACHING ;
44const jsHelpers = require ( '../lib/helpers/js-helpers' ) ;
55
6+ function sleep ( ms ) {
7+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
8+ }
9+
610/** FOR FINDING ERRANT LOGS **/
711if ( process . env . SHOW_LOG_LOCATION == 'true' || 1 == 2 ) {
812 jsHelpers . showLogLocation ( ) ;
@@ -76,6 +80,7 @@ async function cacheOnlyRecentUploads(){
7680async function cachePopularDailyStatsAndIndex ( ) {
7781 try {
7882 await cachePopularUploads ( ) ;
83+ await calculateUploadViews ( ) ;
7984 await setCache . setDailyStats ( ) ;
8085 await setCache . setIndexValues ( ) ;
8186
@@ -108,26 +113,42 @@ console.log(`CACHE TOTAL VIEW INTERVAL IN MINUTES: ${cacheIntervalInMinutes} \n`
108113// TODO: ideally, they should push into an array, run the most recent job in array, then delete it from array,
109114// TODO: and run them sequentially
110115
111- async function main ( ) {
112-
113- // setInterval(cacheOnlyRecentUploads, cacheRecentIntervalInMs);
114- //
115- // setInterval(cachePopularDailyStatsAndIndex, cacheIntervalInMs);
116- //
117- // // calculate total amount of views for channel display
118- // // TODO: couldn't this just be done during popular? maybe not because it doesn't do for sensitive?
119- // // TODO: then just do a separate job for
120- // setInterval(calculateUploadViews, cacheTotalViewsIntervalInMs);
121-
116+ async function runRecentInterval ( ) {
122117 // calculate and cache recent uploads every minute
123118 await cacheOnlyRecentUploads ( ) ;
119+ await sleep ( cacheRecentIntervalInMs )
120+ runRecentInterval ( ) ;
121+ }
124122
125- await cachePopularDailyStatsAndIndex ( ) ;
123+ runRecentInterval ( ) ;
126124
127- await calculateUploadViews ( ) ;
125+ async function runOtherCaching ( ) {
126+ await cachePopularDailyStatsAndIndex ( ) ;
127+ await sleep ( cacheIntervalInMs )
128+ runOtherCaching ( )
128129}
129130
130- main ( ) ;
131+ runOtherCaching ( )
132+
133+ // async function main(){
134+ //
135+ // // setInterval(cacheOnlyRecentUploads, cacheRecentIntervalInMs);
136+ // //
137+ // // setInterval(cachePopularDailyStatsAndIndex, cacheIntervalInMs);
138+ // //
139+ // // // calculate total amount of views for channel display
140+ // // // TODO: couldn't this just be done during popular? maybe not because it doesn't do for sensitive?
141+ // // // TODO: then just do a separate job for
142+ // // setInterval(calculateUploadViews, cacheTotalViewsIntervalInMs);
143+ //
144+ // // calculate and cache recent uploads every minute
145+ // // await cacheOnlyRecentUploads();
146+ //
147+ // // also does total view amounts
148+ // await cachePopularDailyStatsAndIndex();
149+ // }
150+
151+ // main();
131152
132153// calculateUploadViews()
133154
0 commit comments