packages/cron/src/jobs/metrics.js
/**
 * Calculate metrics from RO DB and update their current values in the RW DB.
 *
 * @param {{ rwPg: Client, roPg: Client }} config
 */
Calculate metrics from RO DB and update their current values in the RW DB.
@param {{ rwPg: Client, roPg: Client }} config
Calculate metrics from RO DB and update their current values in the RW DB . @param {{ rwPg : Client roPg : Client }} config
async function updateMetrics({ roPg, rwPg }) {
  const results = await settle(
    [
      withTimeLog('updateUsersCount', () => updateUsersCount(roPg, rwPg)),
      withTimeLog('updateContentRootDagSizeSum', () =>
        updateContentRootDagSizeSum(roPg, rwPg)
      ),
      ...UPLOAD_TYPES.map((t) =>
        withTimeLog(`updateUploadsCount[${t}]`, () =>
          updateUploadsCount(roPg, rwPg, t)
        )
      ),
      withTimeLog('updateTotalUploadPast7', () =>
        updateTotalUploadPast7(roPg, rwPg)
      ),
      ...PIN_SERVICES.map((svc) =>
        PIN_STATUSES.map((s) =>
          withTimeLog(`updatePinsCount[${svc}][${s}]`, () =>
            updatePinsCount(roPg, rwPg, svc, s)
          )
        )
      ).flat(),
    ],
    { concurrency: MAX_CONCURRENT_QUERIES }
  )
  let error
  for (const promise of results) {
    if (promise.isFulfilled) continue
    error = error || promise.reason
    console.error(promise.reason)
  }
  if (error) throw error
  log('✅ Done')
}
async function updateMetrics ( { roPg , rwPg } ) { const results = await settle ( [ withTimeLog ( 'updateUsersCount' , ( ) => updateUsersCount ( roPg , rwPg ) ) , withTimeLog ( 'updateContentRootDagSizeSum' , ( ) => updateContentRootDagSizeSum ( roPg , rwPg ) ) , ... UPLOAD_TYPES . map ( ( t ) => withTimeLog ( ` ${ t } ` , ( ) => updateUploadsCount ( roPg , rwPg , t ) ) ) , withTimeLog ( 'updateTotalUploadPast7' , ( ) => updateTotalUploadPast7 ( roPg , rwPg ) ) , ... PIN_SERVICES . map ( ( svc ) => PIN_STATUSES . map ( ( s ) => withTimeLog ( ` ${ svc } ${ s } ` , ( ) => updatePinsCount ( roPg , rwPg , svc , s ) ) ) ) . flat ( ) , ] , { concurrency : MAX_CONCURRENT_QUERIES } ) let error for ( const promise of results ) { if ( promise . isFulfilled ) continue error = error || promise . reason console . error ( promise . reason ) } if ( error ) throw error log ( '✅ Done') }
Calculate metrics from RO DB and update their current values in the RW DB.
Calculate metrics from RO DB and update their current values in the RW DB .