diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-05 15:15:09 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2 (patch) | |
tree | 887521117856c06e6c814a0eb79d67f85ffe8eff /server/lib | |
parent | d74bb0647c79748860ad39c4b7b1be59504b47b7 (diff) | |
download | PeerTube-dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2.tar.gz PeerTube-dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2.tar.zst PeerTube-dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2.zip |
Improve views/viewers documentation
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/redis.ts | 2 | ||||
-rw-r--r-- | server/lib/views/shared/video-viewers.ts | 7 | ||||
-rw-r--r-- | server/lib/views/video-views-manager.ts | 18 |
3 files changed, 23 insertions, 4 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts index b86aefa0e..f9cea57cd 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts | |||
@@ -146,7 +146,7 @@ class Redis { | |||
146 | } | 146 | } |
147 | 147 | ||
148 | setIPVideoViewer (ip: string, videoUUID: string) { | 148 | setIPVideoViewer (ip: string, videoUUID: string) { |
149 | return this.setValue(this.generateIPViewerKey(ip, videoUUID), '1', VIEW_LIFETIME.VIEWER) | 149 | return this.setValue(this.generateIPViewerKey(ip, videoUUID), '1', VIEW_LIFETIME.VIEWER_COUNTER) |
150 | } | 150 | } |
151 | 151 | ||
152 | async doesVideoIPViewExist (ip: string, videoUUID: string) { | 152 | async doesVideoIPViewExist (ip: string, videoUUID: string) { |
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 { |