diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-04 14:39:47 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-04 15:45:44 +0200 |
commit | fc21ef5c62d845576a916414468b3a57370a57b2 (patch) | |
tree | 818102bc909210870f9a28692361f7b5cbe219de /client/src/app/core | |
parent | 2989628b7913383b39ac34c7db8666a21f8e5037 (diff) | |
download | PeerTube-fc21ef5c62d845576a916414468b3a57370a57b2.tar.gz PeerTube-fc21ef5c62d845576a916414468b3a57370a57b2.tar.zst PeerTube-fc21ef5c62d845576a916414468b3a57370a57b2.zip |
Speed up plugins loading
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/core.module.ts | 8 | ||||
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 26 | ||||
-rw-r--r-- | client/src/app/core/routing/homepage-redirect.component.ts | 30 | ||||
-rw-r--r-- | client/src/app/core/routing/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 1 |
5 files changed, 41 insertions, 25 deletions
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index de3274544..3e2056481 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts | |||
@@ -14,7 +14,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard' | |||
14 | import { Notifier } from './notification' | 14 | import { Notifier } from './notification' |
15 | import { HtmlRendererService, LinkifierService, MarkdownService } from './renderer' | 15 | import { HtmlRendererService, LinkifierService, MarkdownService } from './renderer' |
16 | import { RestExtractor, RestService } from './rest' | 16 | import { RestExtractor, RestService } from './rest' |
17 | import { LoginGuard, MetaGuard, MetaService, RedirectService, UnloggedGuard, UserRightGuard } from './routing' | 17 | import { HomepageRedirectComponent, LoginGuard, MetaGuard, MetaService, RedirectService, UnloggedGuard, UserRightGuard } from './routing' |
18 | import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' | 18 | import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' |
19 | import { ServerConfigResolver } from './routing/server-config-resolver.service' | 19 | import { ServerConfigResolver } from './routing/server-config-resolver.service' |
20 | import { ScopedTokensService } from './scoped-tokens' | 20 | import { ScopedTokensService } from './scoped-tokens' |
@@ -36,13 +36,15 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra | |||
36 | ], | 36 | ], |
37 | 37 | ||
38 | declarations: [ | 38 | declarations: [ |
39 | CheatSheetComponent | 39 | CheatSheetComponent, |
40 | HomepageRedirectComponent | ||
40 | ], | 41 | ], |
41 | 42 | ||
42 | exports: [ | 43 | exports: [ |
43 | ToastModule, | 44 | ToastModule, |
44 | 45 | ||
45 | CheatSheetComponent | 46 | CheatSheetComponent, |
47 | HomepageRedirectComponent | ||
46 | ], | 48 | ], |
47 | 49 | ||
48 | providers: [ | 50 | providers: [ |
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index dff8ad864..ccbfd3e4d 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import * as debug from 'debug' | ||
1 | import { Observable, of, ReplaySubject } from 'rxjs' | 2 | import { Observable, of, ReplaySubject } from 'rxjs' |
2 | import { catchError, first, map, shareReplay } from 'rxjs/operators' | 3 | import { catchError, first, map, shareReplay } from 'rxjs/operators' |
3 | import { HttpClient } from '@angular/common/http' | 4 | import { HttpClient } from '@angular/common/http' |
@@ -24,7 +25,6 @@ import { | |||
24 | } from '@shared/models' | 25 | } from '@shared/models' |
25 | import { environment } from '../../../environments/environment' | 26 | import { environment } from '../../../environments/environment' |
26 | import { RegisterClientHelpers } from '../../../types/register-client-option.model' | 27 | import { RegisterClientHelpers } from '../../../types/register-client-option.model' |
27 | import * as debug from 'debug' | ||
28 | 28 | ||
29 | const logger = debug('peertube:plugins') | 29 | const logger = debug('peertube:plugins') |
30 | 30 | ||
@@ -33,8 +33,6 @@ export class PluginService implements ClientHook { | |||
33 | private static BASE_PLUGIN_API_URL = environment.apiUrl + '/api/v1/plugins' | 33 | private static BASE_PLUGIN_API_URL = environment.apiUrl + '/api/v1/plugins' |
34 | private static BASE_PLUGIN_URL = environment.apiUrl + '/plugins' | 34 | private static BASE_PLUGIN_URL = environment.apiUrl + '/plugins' |
35 | 35 | ||
36 | pluginsBuilt = new ReplaySubject<boolean>(1) | ||
37 | |||
38 | pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = { | 36 | pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = { |
39 | common: new ReplaySubject<boolean>(1), | 37 | common: new ReplaySubject<boolean>(1), |
40 | 'admin-plugin': new ReplaySubject<boolean>(1), | 38 | 'admin-plugin': new ReplaySubject<boolean>(1), |
@@ -79,30 +77,18 @@ export class PluginService implements ClientHook { | |||
79 | } | 77 | } |
80 | 78 | ||
81 | initializePlugins () { | 79 | initializePlugins () { |
82 | logger('Building plugin configuration') | 80 | const config = this.server.getHTMLConfig() |
81 | this.plugins = config.plugin.registered | ||
83 | 82 | ||
84 | this.server.getConfig() | 83 | this.buildScopeStruct() |
85 | .subscribe(config => { | ||
86 | this.plugins = config.plugin.registered | ||
87 | 84 | ||
88 | this.buildScopeStruct() | 85 | this.ensurePluginsAreLoaded('common') |
89 | |||
90 | this.pluginsBuilt.next(true) | ||
91 | |||
92 | logger('Plugin configuration built') | ||
93 | }) | ||
94 | } | 86 | } |
95 | 87 | ||
96 | initializeCustomModal (customModal: CustomModalComponent) { | 88 | initializeCustomModal (customModal: CustomModalComponent) { |
97 | this.customModal = customModal | 89 | this.customModal = customModal |
98 | } | 90 | } |
99 | 91 | ||
100 | ensurePluginsAreBuilt () { | ||
101 | return this.pluginsBuilt.asObservable() | ||
102 | .pipe(first(), shareReplay()) | ||
103 | .toPromise() | ||
104 | } | ||
105 | |||
106 | ensurePluginsAreLoaded (scope: PluginClientScope) { | 92 | ensurePluginsAreLoaded (scope: PluginClientScope) { |
107 | this.loadPluginsByScope(scope) | 93 | this.loadPluginsByScope(scope) |
108 | 94 | ||
@@ -156,8 +142,6 @@ export class PluginService implements ClientHook { | |||
156 | logger('Loading scope %s', scope) | 142 | logger('Loading scope %s', scope) |
157 | 143 | ||
158 | try { | 144 | try { |
159 | await this.ensurePluginsAreBuilt() | ||
160 | |||
161 | if (!isReload) this.loadedScopes.push(scope) | 145 | if (!isReload) this.loadedScopes.push(scope) |
162 | 146 | ||
163 | const toLoad = this.scopes[ scope ] | 147 | const toLoad = this.scopes[ scope ] |
diff --git a/client/src/app/core/routing/homepage-redirect.component.ts b/client/src/app/core/routing/homepage-redirect.component.ts new file mode 100644 index 000000000..9e3848038 --- /dev/null +++ b/client/src/app/core/routing/homepage-redirect.component.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute } from '@angular/router' | ||
3 | import { is18nPath } from '@shared/core-utils/i18n/i18n' | ||
4 | import { RedirectService } from './redirect.service' | ||
5 | |||
6 | /* | ||
7 | * We have to use a component instead of an homepage because of a weird issue when using router.navigate in guard | ||
8 | * | ||
9 | * Since we also want to use the `skipLocationChange` option, we cannot use a guard that returns a UrlTree | ||
10 | * See https://github.com/angular/angular/issues/27148 | ||
11 | */ | ||
12 | |||
13 | @Component({ | ||
14 | template: '' | ||
15 | }) | ||
16 | export class HomepageRedirectComponent implements OnInit { | ||
17 | |||
18 | constructor ( | ||
19 | private route: ActivatedRoute, | ||
20 | private redirectService: RedirectService | ||
21 | ) { } | ||
22 | |||
23 | ngOnInit () { | ||
24 | const url = this.route.snapshot.url | ||
25 | |||
26 | if (url.length === 0 || is18nPath('/' + url[0])) { | ||
27 | this.redirectService.redirectToHomepage(true) | ||
28 | } | ||
29 | } | ||
30 | } | ||
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index 4314ea475..d0c688a2f 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | export * from './can-deactivate-guard.service' | 1 | export * from './can-deactivate-guard.service' |
2 | export * from './custom-reuse-strategy' | 2 | export * from './custom-reuse-strategy' |
3 | export * from './disable-for-reuse-hook' | 3 | export * from './disable-for-reuse-hook' |
4 | export * from './homepage-redirect.component' | ||
4 | export * from './login-guard.service' | 5 | export * from './login-guard.service' |
5 | export * from './menu-guard.service' | 6 | export * from './menu-guard.service' |
6 | export * from './meta-guard.service' | 7 | export * from './meta-guard.service' |
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 198332b00..17d9d1358 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -42,7 +42,6 @@ export class RedirectService { | |||
42 | return this.defaultRoute | 42 | return this.defaultRoute |
43 | } | 43 | } |
44 | 44 | ||
45 | |||
46 | getDefaultTrendingAlgorithm () { | 45 | getDefaultTrendingAlgorithm () { |
47 | return this.defaultTrendingAlgorithm | 46 | return this.defaultTrendingAlgorithm |
48 | } | 47 | } |