]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/views/shared/video-viewer-stats.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / lib / views / shared / video-viewer-stats.ts
index a56c205590711cfded6fecf32d42c7af2a2458ea..ebd963e598f57e90a4939f672d715a15d2693d54 100644 (file)
@@ -1,5 +1,5 @@
 import { Transaction } from 'sequelize/types'
-import { isTestInstance } from '@server/helpers/core-utils'
+import { isTestOrDevInstance } from '@server/helpers/core-utils'
 import { GeoIP } from '@server/helpers/geo-ip'
 import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { MAX_LOCAL_VIEWER_WATCH_SECTIONS, VIEW_LIFETIME } from '@server/initializers/constants'
@@ -104,7 +104,17 @@ export class VideoViewerStats {
       })
     } else {
       const lastSection = stats.watchSections[stats.watchSections.length - 1]
-      lastSection.end = currentTime
+
+      if (lastSection.start > currentTime) {
+        logger.debug('Invalid end watch section %d. Last start record was at %d. Starting a new section.', currentTime, lastSection.start)
+
+        stats.watchSections.push({
+          start: currentTime,
+          end: currentTime
+        })
+      } else {
+        lastSection.end = currentTime
+      }
     }
 
     stats.watchTime = this.buildWatchTimeFromSections(stats.watchSections)
@@ -118,7 +128,7 @@ export class VideoViewerStats {
     if (this.processingViewersStats) return
     this.processingViewersStats = true
 
-    if (!isTestInstance()) logger.info('Processing viewer statistics.', lTags())
+    if (!isTestOrDevInstance()) logger.info('Processing viewer statistics.', lTags())
 
     const now = new Date().getTime()