@@ -7,12 +7,12 @@ import { PostMetric } from '~/shared/utils/prisma/models';
7
7
import dayjs from 'dayjs' ;
8
8
import { templateHandler } from '~/server/db/db-helpers' ;
9
9
import { isDefined } from '~/utils/type-guards' ;
10
- import { capitalize } from '~/utils/string-helpers' ;
11
10
import { getJobDate } from '~/server/jobs/job' ;
11
+ import { capitalize } from '~/utils/string-helpers' ;
12
12
13
13
const log = createLogger ( 'metrics:post' ) ;
14
14
15
- const timePeriods = [ 'day' , 'week' , 'month' , 'year' , 'allTime' ] as const ;
15
+ const timePeriods = [ 'now' , ' day', 'week' , 'month' , 'year' , 'allTime' ] as const ;
16
16
17
17
export const postMetrics = createMetricProcessor ( {
18
18
name : 'Post' ,
@@ -91,8 +91,14 @@ export const postMetrics = createMetricProcessor({
91
91
if ( timePeriod === 'allTime' ) continue ;
92
92
93
93
const windowDuration = lastRunStart - ctx . lastUpdate . valueOf ( ) ;
94
- const windowEnd = dayjs ( lastRunStart ) . subtract ( 1 , timePeriod ) . valueOf ( ) ;
95
- const windowStart = windowEnd - windowDuration ;
94
+ const windowEnd =
95
+ timePeriod === 'now'
96
+ ? dayjs ( lastRunStart ) . valueOf ( )
97
+ : dayjs ( lastRunStart ) . subtract ( 1 , timePeriod ) . valueOf ( ) ;
98
+ const windowStart =
99
+ timePeriod === 'now'
100
+ ? dayjs ( windowEnd ) . subtract ( 1 , 'day' ) . valueOf ( ) - windowDuration
101
+ : windowEnd - windowDuration ;
96
102
97
103
// Fetch affected posts between the timeframe
98
104
const affectedPostIdsQuery = await ctx . pg . cancellableQuery < { id : number } > ( `
0 commit comments