From 67ad83d0faa5924a566bc8260918439614694c85 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 May 2022 14:49:42 +0200 Subject: [PATCH] Fix stats time metric --- server/models/view/local-video-viewer.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/models/view/local-video-viewer.ts b/server/models/view/local-video-viewer.ts index 2305c7262..b8c372040 100644 --- a/server/models/view/local-video-viewer.ts +++ b/server/models/view/local-video-viewer.ts @@ -236,6 +236,16 @@ export class LocalVideoViewerModel extends Model= "intervals"."startDate"', + + // We do an aggregation, so only sum things once. Arbitrary we use the end date for that purpose + aggregateWatchTime: '"localVideoViewer"."endDate" >= "intervals"."startDate" ' + + 'AND "localVideoViewer"."endDate" <= "intervals"."endDate"' + } + const query = `WITH "intervals" AS ( SELECT "time" AS "startDate", "time" + :groupInterval::interval as "endDate" @@ -246,7 +256,7 @@ export class LocalVideoViewerModel extends Model= "intervals"."startDate" AND "localVideoViewer"."startDate" <= "intervals"."endDate" + AND ${intervalWhere[metric]} GROUP BY "intervals"."startDate" ORDER BY