aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/constants.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/constants.ts')
-rw-r--r--server/initializers/constants.ts32
1 files changed, 18 insertions, 14 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 6b4afbfd8..03424ffb8 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -1,11 +1,11 @@
1import { IConfig } from 'config' 1import { IConfig } from 'config'
2import { dirname, join } from 'path' 2import { dirname, join } from 'path'
3import { JobType, VideoRateType, VideoRedundancyStrategy, VideoState, VideosRedundancy } from '../../shared/models' 3import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models'
4import { ActivityPubActorType } from '../../shared/models/activitypub' 4import { ActivityPubActorType } from '../../shared/models/activitypub'
5import { FollowState } from '../../shared/models/actors' 5import { FollowState } from '../../shared/models/actors'
6import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' 6import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos'
7// Do not use barrels, remain constants as independent as possible 7// Do not use barrels, remain constants as independent as possible
8import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' 8import { buildPath, isTestInstance, parseDuration, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10import { invert } from 'lodash' 10import { invert } from 'lodash'
11import { CronRepeatOptions, EveryRepeatOptions } from 'bull' 11import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
@@ -66,7 +66,8 @@ const ROUTE_CACHE_LIFETIME = {
66 }, 66 },
67 ACTIVITY_PUB: { 67 ACTIVITY_PUB: {
68 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example 68 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
69 } 69 },
70 STATS: '4 hours'
70} 71}
71 72
72// --------------------------------------------------------------------------- 73// ---------------------------------------------------------------------------
@@ -138,8 +139,7 @@ let SCHEDULER_INTERVALS_MS = {
138 badActorFollow: 60000 * 60, // 1 hour 139 badActorFollow: 60000 * 60, // 1 hour
139 removeOldJobs: 60000 * 60, // 1 hour 140 removeOldJobs: 60000 * 60, // 1 hour
140 updateVideos: 60000, // 1 minute 141 updateVideos: 60000, // 1 minute
141 youtubeDLUpdate: 60000 * 60 * 24, // 1 day 142 youtubeDLUpdate: 60000 * 60 * 24 // 1 day
142 videosRedundancy: 60000 * 2 // 2 hours
143} 143}
144 144
145// --------------------------------------------------------------------------- 145// ---------------------------------------------------------------------------
@@ -211,7 +211,10 @@ const CONFIG = {
211 } 211 }
212 }, 212 },
213 REDUNDANCY: { 213 REDUNDANCY: {
214 VIDEOS: buildVideosRedundancy(config.get<any[]>('redundancy.videos')) 214 VIDEOS: {
215 CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
216 STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
217 }
215 }, 218 },
216 ADMIN: { 219 ADMIN: {
217 get EMAIL () { return config.get<string>('admin.email') } 220 get EMAIL () { return config.get<string>('admin.email') }
@@ -592,6 +595,10 @@ const CACHE = {
592 } 595 }
593} 596}
594 597
598const MEMOIZE_TTL = {
599 OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours
600}
601
595const REDUNDANCY = { 602const REDUNDANCY = {
596 VIDEOS: { 603 VIDEOS: {
597 EXPIRES_AFTER_MS: 48 * 3600 * 1000, // 2 days 604 EXPIRES_AFTER_MS: 48 * 3600 * 1000, // 2 days
@@ -644,7 +651,6 @@ if (isTestInstance() === true) {
644 SCHEDULER_INTERVALS_MS.badActorFollow = 10000 651 SCHEDULER_INTERVALS_MS.badActorFollow = 10000
645 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 652 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
646 SCHEDULER_INTERVALS_MS.updateVideos = 5000 653 SCHEDULER_INTERVALS_MS.updateVideos = 5000
647 SCHEDULER_INTERVALS_MS.videosRedundancy = 5000
648 REPEAT_JOBS['videos-views'] = { every: 5000 } 654 REPEAT_JOBS['videos-views'] = { every: 5000 }
649 655
650 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 656 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
@@ -654,6 +660,8 @@ if (isTestInstance() === true) {
654 JOB_ATTEMPTS['email'] = 1 660 JOB_ATTEMPTS['email'] = 1
655 661
656 CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 662 CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
663 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
664 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
657} 665}
658 666
659updateWebserverConfig() 667updateWebserverConfig()
@@ -708,6 +716,7 @@ export {
708 VIDEO_ABUSE_STATES, 716 VIDEO_ABUSE_STATES,
709 JOB_REQUEST_TIMEOUT, 717 JOB_REQUEST_TIMEOUT,
710 USER_PASSWORD_RESET_LIFETIME, 718 USER_PASSWORD_RESET_LIFETIME,
719 MEMOIZE_TTL,
711 USER_EMAIL_VERIFY_LIFETIME, 720 USER_EMAIL_VERIFY_LIFETIME,
712 IMAGE_MIMETYPE_EXT, 721 IMAGE_MIMETYPE_EXT,
713 OVERVIEWS, 722 OVERVIEWS,
@@ -741,15 +750,10 @@ function updateWebserverConfig () {
741 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) 750 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
742} 751}
743 752
744function buildVideosRedundancy (objs: { strategy: VideoRedundancyStrategy, size: string }[]): VideosRedundancy[] { 753function buildVideosRedundancy (objs: VideosRedundancy[]): VideosRedundancy[] {
745 if (!objs) return [] 754 if (!objs) return []
746 755
747 return objs.map(obj => { 756 return objs.map(obj => Object.assign(obj, { size: bytes.parse(obj.size) }))
748 return {
749 strategy: obj.strategy,
750 size: bytes.parse(obj.size)
751 }
752 })
753} 757}
754 758
755function buildLanguages () { 759function buildLanguages () {