diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 22 | ||||
-rw-r--r-- | server/initializers/migrations/0420-avatar-lazy.ts | 60 |
2 files changed, 78 insertions, 4 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index b9d90b2bd..3dc178b11 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
14 | 14 | ||
15 | // --------------------------------------------------------------------------- | 15 | // --------------------------------------------------------------------------- |
16 | 16 | ||
17 | const LAST_MIGRATION_VERSION = 415 | 17 | const LAST_MIGRATION_VERSION = 420 |
18 | 18 | ||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
20 | 20 | ||
@@ -498,6 +498,11 @@ const STATIC_DOWNLOAD_PATHS = { | |||
498 | TORRENTS: '/download/torrents/', | 498 | TORRENTS: '/download/torrents/', |
499 | VIDEOS: '/download/videos/' | 499 | VIDEOS: '/download/videos/' |
500 | } | 500 | } |
501 | const LAZY_STATIC_PATHS = { | ||
502 | AVATARS: '/lazy-static/avatars/', | ||
503 | PREVIEWS: '/static/previews/', | ||
504 | VIDEO_CAPTIONS: '/static/video-captions/' | ||
505 | } | ||
501 | 506 | ||
502 | // Cache control | 507 | // Cache control |
503 | let STATIC_MAX_AGE = { | 508 | let STATIC_MAX_AGE = { |
@@ -536,9 +541,12 @@ const FILES_CACHE = { | |||
536 | } | 541 | } |
537 | } | 542 | } |
538 | 543 | ||
539 | const CACHE = { | 544 | const LRU_CACHE = { |
540 | USER_TOKENS: { | 545 | USER_TOKENS: { |
541 | MAX_SIZE: 10000 | 546 | MAX_SIZE: 1000 |
547 | }, | ||
548 | AVATAR_STATIC: { | ||
549 | MAX_SIZE: 500 | ||
542 | } | 550 | } |
543 | } | 551 | } |
544 | 552 | ||
@@ -549,6 +557,10 @@ const MEMOIZE_TTL = { | |||
549 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours | 557 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours |
550 | } | 558 | } |
551 | 559 | ||
560 | const QUEUE_CONCURRENCY = { | ||
561 | AVATAR_PROCESS_IMAGE: 3 | ||
562 | } | ||
563 | |||
552 | const REDUNDANCY = { | 564 | const REDUNDANCY = { |
553 | VIDEOS: { | 565 | VIDEOS: { |
554 | RANDOMIZED_FACTOR: 5 | 566 | RANDOMIZED_FACTOR: 5 |
@@ -649,6 +661,7 @@ export { | |||
649 | WEBSERVER, | 661 | WEBSERVER, |
650 | API_VERSION, | 662 | API_VERSION, |
651 | PEERTUBE_VERSION, | 663 | PEERTUBE_VERSION, |
664 | LAZY_STATIC_PATHS, | ||
652 | HLS_REDUNDANCY_DIRECTORY, | 665 | HLS_REDUNDANCY_DIRECTORY, |
653 | P2P_MEDIA_LOADER_PEER_VERSION, | 666 | P2P_MEDIA_LOADER_PEER_VERSION, |
654 | AVATARS_SIZE, | 667 | AVATARS_SIZE, |
@@ -695,11 +708,12 @@ export { | |||
695 | VIDEO_PRIVACIES, | 708 | VIDEO_PRIVACIES, |
696 | VIDEO_LICENCES, | 709 | VIDEO_LICENCES, |
697 | VIDEO_STATES, | 710 | VIDEO_STATES, |
711 | QUEUE_CONCURRENCY, | ||
698 | VIDEO_RATE_TYPES, | 712 | VIDEO_RATE_TYPES, |
699 | VIDEO_TRANSCODING_FPS, | 713 | VIDEO_TRANSCODING_FPS, |
700 | FFMPEG_NICE, | 714 | FFMPEG_NICE, |
701 | VIDEO_ABUSE_STATES, | 715 | VIDEO_ABUSE_STATES, |
702 | CACHE, | 716 | LRU_CACHE, |
703 | JOB_REQUEST_TIMEOUT, | 717 | JOB_REQUEST_TIMEOUT, |
704 | USER_PASSWORD_RESET_LIFETIME, | 718 | USER_PASSWORD_RESET_LIFETIME, |
705 | MEMOIZE_TTL, | 719 | MEMOIZE_TTL, |
diff --git a/server/initializers/migrations/0420-avatar-lazy.ts b/server/initializers/migrations/0420-avatar-lazy.ts new file mode 100644 index 000000000..5fc57aac2 --- /dev/null +++ b/server/initializers/migrations/0420-avatar-lazy.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize, | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | // We'll add a unique index on filename, so delete duplicates or PeerTube won't start | ||
11 | const query = 'DELETE FROM "avatar" s1 ' + | ||
12 | 'USING (SELECT MIN(id) as id, filename FROM "avatar" GROUP BY "filename" HAVING COUNT(*) > 1) s2 ' + | ||
13 | 'WHERE s1."filename" = s2."filename" AND s1.id <> s2.id' | ||
14 | await utils.sequelize.query(query) | ||
15 | } | ||
16 | |||
17 | { | ||
18 | const data = { | ||
19 | type: Sequelize.STRING, | ||
20 | allowNull: true, | ||
21 | defaultValue: null | ||
22 | } | ||
23 | |||
24 | await utils.queryInterface.addColumn('avatar', 'fileUrl', data) | ||
25 | } | ||
26 | |||
27 | { | ||
28 | const data = { | ||
29 | type: Sequelize.BOOLEAN, | ||
30 | allowNull: true, | ||
31 | defaultValue: null | ||
32 | } | ||
33 | |||
34 | await utils.queryInterface.addColumn('avatar', 'onDisk', data) | ||
35 | } | ||
36 | |||
37 | { | ||
38 | const query = 'UPDATE "avatar" SET "onDisk" = true;' | ||
39 | await utils.sequelize.query(query) | ||
40 | } | ||
41 | |||
42 | { | ||
43 | const data = { | ||
44 | type: Sequelize.BOOLEAN, | ||
45 | allowNull: false, | ||
46 | defaultValue: null | ||
47 | } | ||
48 | |||
49 | await utils.queryInterface.changeColumn('avatar', 'onDisk', data) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | function down (options) { | ||
54 | throw new Error('Not implemented.') | ||
55 | } | ||
56 | |||
57 | export { | ||
58 | up, | ||
59 | down | ||
60 | } | ||