diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/checker.ts | 16 | ||||
-rw-r--r-- | server/initializers/constants.ts | 32 |
2 files changed, 30 insertions, 18 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index 6a2badd35..a54f6155b 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -7,7 +7,7 @@ import { parse } from 'url' | |||
7 | import { CONFIG } from './constants' | 7 | import { CONFIG } from './constants' |
8 | import { logger } from '../helpers/logger' | 8 | import { logger } from '../helpers/logger' |
9 | import { getServerActor } from '../helpers/utils' | 9 | import { getServerActor } from '../helpers/utils' |
10 | import { VideosRedundancy } from '../../shared/models/redundancy' | 10 | import { RecentlyAddedStrategy, VideosRedundancy } from '../../shared/models/redundancy' |
11 | import { isArray } from '../helpers/custom-validators/misc' | 11 | import { isArray } from '../helpers/custom-validators/misc' |
12 | import { uniq } from 'lodash' | 12 | import { uniq } from 'lodash' |
13 | 13 | ||
@@ -34,21 +34,28 @@ async function checkActivityPubUrls () { | |||
34 | function checkConfig () { | 34 | function checkConfig () { |
35 | const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy') | 35 | const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy') |
36 | 36 | ||
37 | // NSFW policy | ||
37 | if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) { | 38 | if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) { |
38 | return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy | 39 | return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy |
39 | } | 40 | } |
40 | 41 | ||
41 | const redundancyVideos = config.get<VideosRedundancy[]>('redundancy.videos') | 42 | // Redundancies |
43 | const redundancyVideos = config.get<VideosRedundancy[]>('redundancy.videos.strategies') | ||
42 | if (isArray(redundancyVideos)) { | 44 | if (isArray(redundancyVideos)) { |
43 | for (const r of redundancyVideos) { | 45 | for (const r of redundancyVideos) { |
44 | if ([ 'most-views' ].indexOf(r.strategy) === -1) { | 46 | if ([ 'most-views', 'trending', 'recently-added' ].indexOf(r.strategy) === -1) { |
45 | return 'Redundancy video entries should have "most-views" strategy instead of ' + r.strategy | 47 | return 'Redundancy video entries should have "most-views" strategy instead of ' + r.strategy |
46 | } | 48 | } |
47 | } | 49 | } |
48 | 50 | ||
49 | const filtered = uniq(redundancyVideos.map(r => r.strategy)) | 51 | const filtered = uniq(redundancyVideos.map(r => r.strategy)) |
50 | if (filtered.length !== redundancyVideos.length) { | 52 | if (filtered.length !== redundancyVideos.length) { |
51 | return 'Redundancy video entries should have uniq strategies' | 53 | return 'Redundancy video entries should have unique strategies' |
54 | } | ||
55 | |||
56 | const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy | ||
57 | if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { | ||
58 | return 'Min views in recently added strategy is not a number' | ||
52 | } | 59 | } |
53 | } | 60 | } |
54 | 61 | ||
@@ -68,6 +75,7 @@ function checkMissedConfig () { | |||
68 | 'cache.previews.size', 'admin.email', | 75 | 'cache.previews.size', 'admin.email', |
69 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', | 76 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', |
70 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | 77 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', |
78 | 'redundancy.videos.strategies', 'redundancy.videos.check_interval', | ||
71 | 'transcoding.enabled', 'transcoding.threads', | 79 | 'transcoding.enabled', 'transcoding.threads', |
72 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', | 80 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', |
73 | 'trending.videos.interval_days', | 81 | 'trending.videos.interval_days', |
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 @@ | |||
1 | import { IConfig } from 'config' | 1 | import { IConfig } from 'config' |
2 | import { dirname, join } from 'path' | 2 | import { dirname, join } from 'path' |
3 | import { JobType, VideoRateType, VideoRedundancyStrategy, VideoState, VideosRedundancy } from '../../shared/models' | 3 | import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models' |
4 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 4 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
5 | import { FollowState } from '../../shared/models/actors' | 5 | import { FollowState } from '../../shared/models/actors' |
6 | import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' | 6 | import { 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 |
8 | import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 8 | import { buildPath, isTestInstance, parseDuration, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | 9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
10 | import { invert } from 'lodash' | 10 | import { invert } from 'lodash' |
11 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | 11 | import { 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 | ||
598 | const MEMOIZE_TTL = { | ||
599 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours | ||
600 | } | ||
601 | |||
595 | const REDUNDANCY = { | 602 | const 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 | ||
659 | updateWebserverConfig() | 667 | updateWebserverConfig() |
@@ -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 | ||
744 | function buildVideosRedundancy (objs: { strategy: VideoRedundancyStrategy, size: string }[]): VideosRedundancy[] { | 753 | function 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 | ||
755 | function buildLanguages () { | 759 | function buildLanguages () { |