diff options
Diffstat (limited to 'server/lib/views')
-rw-r--r-- | server/lib/views/shared/video-viewers.ts | 7 | ||||
-rw-r--r-- | server/lib/views/video-views-manager.ts | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/server/lib/views/shared/video-viewers.ts b/server/lib/views/shared/video-viewers.ts index 5c26f8982..4dad1f0e8 100644 --- a/server/lib/views/shared/video-viewers.ts +++ b/server/lib/views/shared/video-viewers.ts | |||
@@ -41,7 +41,7 @@ export class VideoViewers { | |||
41 | private processingViewerStats = false | 41 | private processingViewerStats = false |
42 | 42 | ||
43 | constructor () { | 43 | constructor () { |
44 | setInterval(() => this.cleanViewerCounters(), VIEW_LIFETIME.VIEWER) | 44 | setInterval(() => this.cleanViewerCounters(), VIEW_LIFETIME.VIEWER_COUNTER) |
45 | 45 | ||
46 | setInterval(() => this.processViewerStats(), VIEW_LIFETIME.VIEWER_STATS) | 46 | setInterval(() => this.processViewerStats(), VIEW_LIFETIME.VIEWER_STATS) |
47 | } | 47 | } |
@@ -56,7 +56,7 @@ export class VideoViewers { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | buildViewerExpireTime () { | 58 | buildViewerExpireTime () { |
59 | return new Date().getTime() + VIEW_LIFETIME.VIEWER | 59 | return new Date().getTime() + VIEW_LIFETIME.VIEWER_COUNTER |
60 | } | 60 | } |
61 | 61 | ||
62 | async getWatchTime (videoId: number, ip: string) { | 62 | async getWatchTime (videoId: number, ip: string) { |
@@ -210,7 +210,7 @@ export class VideoViewers { | |||
210 | if (this.processingViewerStats) return | 210 | if (this.processingViewerStats) return |
211 | this.processingViewerStats = true | 211 | this.processingViewerStats = true |
212 | 212 | ||
213 | if (!isTestInstance()) logger.info('Processing viewers.', lTags()) | 213 | if (!isTestInstance()) logger.info('Processing viewer statistics.', lTags()) |
214 | 214 | ||
215 | const now = new Date().getTime() | 215 | const now = new Date().getTime() |
216 | 216 | ||
@@ -220,6 +220,7 @@ export class VideoViewers { | |||
220 | for (const key of allKeys) { | 220 | for (const key of allKeys) { |
221 | const stats: LocalViewerStats = await Redis.Instance.getLocalVideoViewer({ key }) | 221 | const stats: LocalViewerStats = await Redis.Instance.getLocalVideoViewer({ key }) |
222 | 222 | ||
223 | // Process expired stats | ||
223 | if (stats.lastUpdated > now - VIEW_LIFETIME.VIEWER_STATS) { | 224 | if (stats.lastUpdated > now - VIEW_LIFETIME.VIEWER_STATS) { |
224 | continue | 225 | continue |
225 | } | 226 | } |
diff --git a/server/lib/views/video-views-manager.ts b/server/lib/views/video-views-manager.ts index e07af1ca9..9382fb482 100644 --- a/server/lib/views/video-views-manager.ts +++ b/server/lib/views/video-views-manager.ts | |||
@@ -3,6 +3,24 @@ import { MVideo } from '@server/types/models' | |||
3 | import { VideoViewEvent } from '@shared/models' | 3 | import { VideoViewEvent } from '@shared/models' |
4 | import { VideoViewers, VideoViews } from './shared' | 4 | import { VideoViewers, VideoViews } from './shared' |
5 | 5 | ||
6 | /** | ||
7 | * If processing a local view: | ||
8 | * - We update viewer information (segments watched, watch time etc) | ||
9 | * - We add +1 to video viewers counter if this is a new viewer | ||
10 | * - We add +1 to video views counter if this is a new view and if the user watched enough seconds | ||
11 | * - We send AP message to notify about this viewer and this view | ||
12 | * - We update last video time for the user if authenticated | ||
13 | * | ||
14 | * If processing a remote view: | ||
15 | * - We add +1 to video viewers counter | ||
16 | * - We add +1 to video views counter | ||
17 | * | ||
18 | * A viewer is a someone that watched one or multiple sections of a video | ||
19 | * A viewer that watched only a few seconds of a video may not increment the video views counter | ||
20 | * Viewers statistics are sent to origin instance using the `WatchAction` ActivityPub object | ||
21 | * | ||
22 | */ | ||
23 | |||
6 | const lTags = loggerTagsFactory('views') | 24 | const lTags = loggerTagsFactory('views') |
7 | 25 | ||
8 | export class VideoViewsManager { | 26 | export class VideoViewsManager { |