diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-19 16:12:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-19 16:12:07 +0200 |
commit | d9bdd007d7a1368d2a13127ecb5c0a81a18a8c04 (patch) | |
tree | 67cb4d2774dd7127499b882a5aa5069ea6fa86b2 | |
parent | 12ba460e9ebf4951f9c1caee8822a8ca1523563f (diff) | |
download | PeerTube-d9bdd007d7a1368d2a13127ecb5c0a81a18a8c04.tar.gz PeerTube-d9bdd007d7a1368d2a13127ecb5c0a81a18a8c04.tar.zst PeerTube-d9bdd007d7a1368d2a13127ecb5c0a81a18a8c04.zip |
Put config redundancy strategies in "strategies" subkey
-rw-r--r-- | config/default.yaml | 21 | ||||
-rw-r--r-- | config/production.yaml.example | 21 | ||||
-rw-r--r-- | config/test.yaml | 21 | ||||
-rw-r--r-- | server/controllers/api/server/stats.ts | 2 | ||||
-rw-r--r-- | server/initializers/checker.ts | 3 | ||||
-rw-r--r-- | server/initializers/constants.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/actor.ts | 3 | ||||
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 6 | ||||
-rw-r--r-- | server/models/video/tag.ts | 5 |
9 files changed, 46 insertions, 40 deletions
diff --git a/config/default.yaml b/config/default.yaml index ab07bfedd..00eeaea8c 100644 --- a/config/default.yaml +++ b/config/default.yaml | |||
@@ -71,16 +71,17 @@ trending: | |||
71 | # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following | 71 | # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following |
72 | redundancy: | 72 | redundancy: |
73 | videos: | 73 | videos: |
74 | # - | 74 | strategies: |
75 | # size: '10GB' | 75 | # - |
76 | # strategy: 'most-views' # Cache videos that have the most views | 76 | # size: '10GB' |
77 | # - | 77 | # strategy: 'most-views' # Cache videos that have the most views |
78 | # size: '10GB' | 78 | # - |
79 | # strategy: 'trending' # Cache trending videos | 79 | # size: '10GB' |
80 | # - | 80 | # strategy: 'trending' # Cache trending videos |
81 | # size: '10GB' | 81 | # - |
82 | # strategy: 'recently-added' # Cache recently added videos | 82 | # size: '10GB' |
83 | # minViews: 10 # Having at least x views | 83 | # strategy: 'recently-added' # Cache recently added videos |
84 | # minViews: 10 # Having at least x views | ||
84 | 85 | ||
85 | cache: | 86 | cache: |
86 | previews: | 87 | previews: |
diff --git a/config/production.yaml.example b/config/production.yaml.example index f9557b8eb..28770e480 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example | |||
@@ -72,16 +72,17 @@ trending: | |||
72 | # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following | 72 | # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following |
73 | redundancy: | 73 | redundancy: |
74 | videos: | 74 | videos: |
75 | # - | 75 | strategies: |
76 | # size: '10GB' | 76 | # - |
77 | # strategy: 'most-views' # Cache videos that have the most views | 77 | # size: '10GB' |
78 | # - | 78 | # strategy: 'most-views' # Cache videos that have the most views |
79 | # size: '10GB' | 79 | # - |
80 | # strategy: 'trending' # Cache trending videos | 80 | # size: '10GB' |
81 | # - | 81 | # strategy: 'trending' # Cache trending videos |
82 | # size: '10GB' | 82 | # - |
83 | # strategy: 'recently-added' # Cache recently added videos | 83 | # size: '10GB' |
84 | # minViews: 10 # Having at least x views | 84 | # strategy: 'recently-added' # Cache recently added videos |
85 | # minViews: 10 # Having at least x views | ||
85 | 86 | ||
86 | ############################################################################### | 87 | ############################################################################### |
87 | # | 88 | # |
diff --git a/config/test.yaml b/config/test.yaml index d3e0e49ac..d36d90bbd 100644 --- a/config/test.yaml +++ b/config/test.yaml | |||
@@ -23,16 +23,17 @@ log: | |||
23 | 23 | ||
24 | redundancy: | 24 | redundancy: |
25 | videos: | 25 | videos: |
26 | - | 26 | strategies: |
27 | size: '10MB' | 27 | - |
28 | strategy: 'most-views' | 28 | size: '10MB' |
29 | - | 29 | strategy: 'most-views' |
30 | size: '10MB' | 30 | - |
31 | strategy: 'trending' | 31 | size: '10MB' |
32 | - | 32 | strategy: 'trending' |
33 | size: '10MB' | 33 | - |
34 | strategy: 'recently-added' | 34 | size: '10MB' |
35 | minViews: 1 | 35 | strategy: 'recently-added' |
36 | minViews: 1 | ||
36 | 37 | ||
37 | cache: | 38 | cache: |
38 | previews: | 39 | previews: |
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index bb6311e81..85803f69e 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -23,7 +23,7 @@ async function getStats (req: express.Request, res: express.Response, next: expr | |||
23 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() | 23 | const { totalInstanceFollowers, totalInstanceFollowing } = await ActorFollowModel.getStats() |
24 | 24 | ||
25 | const videosRedundancyStats = await Promise.all( | 25 | const videosRedundancyStats = await Promise.all( |
26 | CONFIG.REDUNDANCY.VIDEOS.map(r => { | 26 | CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.map(r => { |
27 | return VideoRedundancyModel.getStats(r.strategy) | 27 | return VideoRedundancyModel.getStats(r.strategy) |
28 | .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) | 28 | .then(stats => Object.assign(stats, { strategy: r.strategy, totalSize: r.size })) |
29 | }) | 29 | }) |
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index b9dc1e725..8b5280848 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -40,7 +40,7 @@ function checkConfig () { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | // Redundancies | 42 | // Redundancies |
43 | const redundancyVideos = config.get<VideosRedundancy[]>('redundancy.videos') | 43 | const redundancyVideos = config.get<VideosRedundancy[]>('redundancy.videos.strategies') |
44 | if (isArray(redundancyVideos)) { | 44 | if (isArray(redundancyVideos)) { |
45 | for (const r of redundancyVideos) { | 45 | for (const r of redundancyVideos) { |
46 | if ([ 'most-views', 'trending', 'recently-added' ].indexOf(r.strategy) === -1) { | 46 | if ([ 'most-views', 'trending', 'recently-added' ].indexOf(r.strategy) === -1) { |
@@ -75,6 +75,7 @@ function checkMissedConfig () { | |||
75 | 'cache.previews.size', 'admin.email', | 75 | 'cache.previews.size', 'admin.email', |
76 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', | 76 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', |
77 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | 77 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', |
78 | 'redundancy.videos.strategies', | ||
78 | 'transcoding.enabled', 'transcoding.threads', | 79 | 'transcoding.enabled', 'transcoding.threads', |
79 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', | 80 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', |
80 | 'trending.videos.interval_days', | 81 | 'trending.videos.interval_days', |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index fa9093918..881978753 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -212,7 +212,9 @@ const CONFIG = { | |||
212 | } | 212 | } |
213 | }, | 213 | }, |
214 | REDUNDANCY: { | 214 | REDUNDANCY: { |
215 | VIDEOS: buildVideosRedundancy(config.get<any[]>('redundancy.videos')) | 215 | VIDEOS: { |
216 | STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies')) | ||
217 | } | ||
216 | }, | 218 | }, |
217 | ADMIN: { | 219 | ADMIN: { |
218 | get EMAIL () { return config.get<string>('admin.email') } | 220 | get EMAIL () { return config.get<string>('admin.email') } |
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 0bdb7d12e..d37a695a7 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -78,6 +78,9 @@ async function getOrCreateActorAndServerAndModel ( | |||
78 | created = true | 78 | created = true |
79 | } | 79 | } |
80 | 80 | ||
81 | if (actor.Account) actor.Account.Actor = actor | ||
82 | if (actor.VideoChannel) actor.VideoChannel.Actor = actor | ||
83 | |||
81 | const { actor: actorRefreshed, refreshed } = await retryTransactionWrapper(refreshActorIfNeeded, actor, fetchType) | 84 | const { actor: actorRefreshed, refreshed } = await retryTransactionWrapper(refreshActorIfNeeded, actor, fetchType) |
82 | if (!actorRefreshed) throw new Error('Actor ' + actorRefreshed.url + ' does not exist anymore.') | 85 | if (!actorRefreshed) throw new Error('Actor ' + actorRefreshed.url + ' does not exist anymore.') |
83 | 86 | ||
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 7079600a9..5f9fd9911 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { AbstractScheduler } from './abstract-scheduler' | 1 | import { AbstractScheduler } from './abstract-scheduler' |
2 | import { CONFIG, JOB_TTL, REDUNDANCY, SCHEDULER_INTERVALS_MS } from '../../initializers' | 2 | import { CONFIG, JOB_TTL, REDUNDANCY, SCHEDULER_INTERVALS_MS } from '../../initializers' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { RecentlyAddedStrategy, VideoRedundancyStrategy, VideosRedundancy } from '../../../shared/models/redundancy' | 4 | import { VideoRedundancyStrategy, VideosRedundancy } from '../../../shared/models/redundancy' |
5 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 5 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
6 | import { VideoFileModel } from '../../models/video/video-file' | 6 | import { VideoFileModel } from '../../models/video/video-file' |
7 | import { sortBy } from 'lodash' | ||
8 | import { downloadWebTorrentVideo } from '../../helpers/webtorrent' | 7 | import { downloadWebTorrentVideo } from '../../helpers/webtorrent' |
9 | import { join } from 'path' | 8 | import { join } from 'path' |
10 | import { rename } from 'fs-extra' | 9 | import { rename } from 'fs-extra' |
@@ -12,7 +11,6 @@ import { getServerActor } from '../../helpers/utils' | |||
12 | import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' | 11 | import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' |
13 | import { VideoModel } from '../../models/video/video' | 12 | import { VideoModel } from '../../models/video/video' |
14 | import { getVideoCacheFileActivityPubUrl } from '../activitypub/url' | 13 | import { getVideoCacheFileActivityPubUrl } from '../activitypub/url' |
15 | import { removeVideoRedundancy } from '../redundancy' | ||
16 | import { isTestInstance } from '../../helpers/core-utils' | 14 | import { isTestInstance } from '../../helpers/core-utils' |
17 | 15 | ||
18 | export class VideosRedundancyScheduler extends AbstractScheduler { | 16 | export class VideosRedundancyScheduler extends AbstractScheduler { |
@@ -31,7 +29,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
31 | 29 | ||
32 | this.executing = true | 30 | this.executing = true |
33 | 31 | ||
34 | for (const obj of CONFIG.REDUNDANCY.VIDEOS) { | 32 | for (const obj of CONFIG.REDUNDANCY.VIDEOS.STRATEGIES) { |
35 | try { | 33 | try { |
36 | const videoToDuplicate = await this.findVideoToDuplicate(obj) | 34 | const videoToDuplicate = await this.findVideoToDuplicate(obj) |
37 | if (!videoToDuplicate) continue | 35 | if (!videoToDuplicate) continue |
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index e39a418cd..b39621eaf 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts | |||
@@ -48,11 +48,10 @@ export class TagModel extends Model<TagModel> { | |||
48 | }, | 48 | }, |
49 | defaults: { | 49 | defaults: { |
50 | name: tag | 50 | name: tag |
51 | } | 51 | }, |
52 | transaction | ||
52 | } | 53 | } |
53 | 54 | ||
54 | if (transaction) query['transaction'] = transaction | ||
55 | |||
56 | const promise = TagModel.findOrCreate(query) | 55 | const promise = TagModel.findOrCreate(query) |
57 | .then(([ tagInstance ]) => tagInstance) | 56 | .then(([ tagInstance ]) => tagInstance) |
58 | tasks.push(promise) | 57 | tasks.push(promise) |