aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-09 10:11:20 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-11-09 15:00:31 +0100
commit51353d9a035fb6b81f903a8b5f391292841649fd (patch)
tree75acb6eea5e043bf2e15a6a5a92e9a3c5967b156 /server/initializers
parent221ee1adc916684d4881d2a9c4c01954dcde986e (diff)
downloadPeerTube-51353d9a035fb6b81f903a8b5f391292841649fd.tar.gz
PeerTube-51353d9a035fb6b81f903a8b5f391292841649fd.tar.zst
PeerTube-51353d9a035fb6b81f903a8b5f391292841649fd.zip
Refactor video views
Introduce viewers attribute for live videos Count views for live videos Reduce delay to see the viewer update for lives Add ability to configure video views buffer interval and view ip expiration
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/config.ts4
-rw-r--r--server/initializers/constants.ts20
3 files changed, 14 insertions, 12 deletions
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 1015c5e45..51c396548 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -38,7 +38,7 @@ function checkMissedConfig () {
38 'services.twitter.username', 'services.twitter.whitelisted', 38 'services.twitter.username', 'services.twitter.whitelisted',
39 'followers.instance.enabled', 'followers.instance.manual_approval', 39 'followers.instance.enabled', 'followers.instance.manual_approval',
40 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces', 40 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces',
41 'history.videos.max_age', 'views.videos.remote.max_age', 41 'history.videos.max_age', 'views.videos.remote.max_age', 'views.videos.local_buffer_update_interval', 'views.videos.ip_view_expiration',
42 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max', 42 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max',
43 'theme.default', 43 'theme.default',
44 'remote_redundancy.videos.accept_from', 44 'remote_redundancy.videos.accept_from',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index 1288768d8..dadda2a77 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -182,7 +182,9 @@ const CONFIG = {
182 VIDEOS: { 182 VIDEOS: {
183 REMOTE: { 183 REMOTE: {
184 MAX_AGE: parseDurationToMs(config.get('views.videos.remote.max_age')) 184 MAX_AGE: parseDurationToMs(config.get('views.videos.remote.max_age'))
185 } 185 },
186 LOCAL_BUFFER_UPDATE_INTERVAL: parseDurationToMs(config.get('views.videos.local_buffer_update_interval')),
187 IP_VIEW_EXPIRATION: parseDurationToMs(config.get('views.videos.ip_view_expiration'))
186 } 188 }
187 }, 189 },
188 PLUGINS: { 190 PLUGINS: {
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 845576667..b65741bbd 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -148,7 +148,7 @@ const JOB_ATTEMPTS: { [id in JobType]: number } = {
148 'video-import': 1, 148 'video-import': 1,
149 'email': 5, 149 'email': 5,
150 'actor-keys': 3, 150 'actor-keys': 3,
151 'videos-views': 1, 151 'videos-views-stats': 1,
152 'activitypub-refresher': 1, 152 'activitypub-refresher': 1,
153 'video-redundancy': 1, 153 'video-redundancy': 1,
154 'video-live-ending': 1, 154 'video-live-ending': 1,
@@ -164,7 +164,7 @@ const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-im
164 'video-file-import': 1, 164 'video-file-import': 1,
165 'email': 5, 165 'email': 5,
166 'actor-keys': 1, 166 'actor-keys': 1,
167 'videos-views': 1, 167 'videos-views-stats': 1,
168 'activitypub-refresher': 1, 168 'activitypub-refresher': 1,
169 'video-redundancy': 1, 169 'video-redundancy': 1,
170 'video-live-ending': 10, 170 'video-live-ending': 10,
@@ -181,14 +181,14 @@ const JOB_TTL: { [id in JobType]: number } = {
181 'video-import': 1000 * 3600 * 2, // 2 hours 181 'video-import': 1000 * 3600 * 2, // 2 hours
182 'email': 60000 * 10, // 10 minutes 182 'email': 60000 * 10, // 10 minutes
183 'actor-keys': 60000 * 20, // 20 minutes 183 'actor-keys': 60000 * 20, // 20 minutes
184 'videos-views': undefined, // Unlimited 184 'videos-views-stats': undefined, // Unlimited
185 'activitypub-refresher': 60000 * 10, // 10 minutes 185 'activitypub-refresher': 60000 * 10, // 10 minutes
186 'video-redundancy': 1000 * 3600 * 3, // 3 hours 186 'video-redundancy': 1000 * 3600 * 3, // 3 hours
187 'video-live-ending': 1000 * 60 * 10, // 10 minutes 187 'video-live-ending': 1000 * 60 * 10, // 10 minutes
188 'move-to-object-storage': 1000 * 60 * 60 * 3 // 3 hours 188 'move-to-object-storage': 1000 * 60 * 60 * 3 // 3 hours
189} 189}
190const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = { 190const REPEAT_JOBS: { [ id in JobType ]?: EveryRepeatOptions | CronRepeatOptions } = {
191 'videos-views': { 191 'videos-views-stats': {
192 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour 192 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
193 }, 193 },
194 'activitypub-cleaner': { 194 'activitypub-cleaner': {
@@ -211,6 +211,7 @@ const SCHEDULER_INTERVALS_MS = {
211 REMOVE_OLD_JOBS: 60000 * 60, // 1 hour 211 REMOVE_OLD_JOBS: 60000 * 60, // 1 hour
212 UPDATE_VIDEOS: 60000, // 1 minute 212 UPDATE_VIDEOS: 60000, // 1 minute
213 YOUTUBE_DL_UPDATE: 60000 * 60 * 24, // 1 day 213 YOUTUBE_DL_UPDATE: 60000 * 60 * 24, // 1 day
214 VIDEO_VIEWS_BUFFER_UPDATE: CONFIG.VIEWS.VIDEOS.LOCAL_BUFFER_UPDATE_INTERVAL,
214 CHECK_PLUGINS: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL, 215 CHECK_PLUGINS: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
215 CHECK_PEERTUBE_VERSION: 60000 * 60 * 24, // 1 day 216 CHECK_PEERTUBE_VERSION: 60000 * 60 * 24, // 1 day
216 AUTO_FOLLOW_INDEX_INSTANCES: 60000 * 60 * 24, // 1 day 217 AUTO_FOLLOW_INDEX_INSTANCES: 60000 * 60 * 24, // 1 day
@@ -343,8 +344,8 @@ const CONSTRAINTS_FIELDS = {
343} 344}
344 345
345const VIEW_LIFETIME = { 346const VIEW_LIFETIME = {
346 VIDEO: 60000 * 60, // 1 hour 347 VIEW: CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION,
347 LIVE: 60000 * 5 // 5 minutes 348 VIEWER: 60000 * 5 // 5 minutes
348} 349}
349 350
350let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour 351let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
@@ -789,13 +790,12 @@ if (isTestInstance() === true) {
789 SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000 790 SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000
790 SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000 791 SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000
791 SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000 792 SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000
792 REPEAT_JOBS['videos-views'] = { every: 5000 } 793 REPEAT_JOBS['videos-views-stats'] = { every: 5000 }
793 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } 794 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
794 795
795 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 796 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
796 797
797 VIEW_LIFETIME.VIDEO = 1000 // 1 second 798 VIEW_LIFETIME.VIEWER = 1000 * 5 // 5 second
798 VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second
799 CONTACT_FORM_LIFETIME = 1000 // 1 second 799 CONTACT_FORM_LIFETIME = 1000 // 1 second
800 800
801 JOB_ATTEMPTS['email'] = 1 801 JOB_ATTEMPTS['email'] = 1