This is an automated email from the ASF dual-hosted git repository.

dominikriemer pushed a commit to branch improve-home-screen-loading-behaviour
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit d454653f926b60d35bb0b7a4f333c2e2e38cd8c0
Author: Dominik Riemer <[email protected]>
AuthorDate: Sat Jun 13 12:53:28 2026 +0200

    Avoid duplicated fetching of login settings
---
 .../registration-allowed.can-activate.guard.ts     |  6 +--
 .../restore-password-allowed.can-activate.guard.ts |  8 ++--
 .../guards/terms.can-activate-children.guard.ts    |  6 +--
 ui/src/app/help/help.component.ts                  |  6 +--
 .../login/components/base-login-page.directive.ts  |  4 +-
 .../services/login-settings.service.ts}            | 50 ++++++++++------------
 ui/src/app/login/services/login.service.ts         | 16 +------
 7 files changed, 40 insertions(+), 56 deletions(-)

diff --git 
a/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts 
b/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts
index ccccc288e5..2b7f1e86ae 100644
--- a/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts
+++ b/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts
@@ -23,14 +23,14 @@ import {
     RouterStateSnapshot,
     UrlTree,
 } from '@angular/router';
-import { LoginService } from '../../../login/services/login.service';
+import { LoginSettingsService } from 
'../../../login/services/login-settings.service';
 import { Observable } from 'rxjs';
 import { map } from 'rxjs/operators';
 
 @Injectable({ providedIn: 'root' })
 export class RegistrationAllowedCanActivateGuard {
     private router = inject(Router);
-    private loginService = inject(LoginService);
+    private loginSettingsService = inject(LoginSettingsService);
 
     canActivate(
         _route: ActivatedRouteSnapshot,
@@ -40,7 +40,7 @@ export class RegistrationAllowedCanActivateGuard {
         | Promise<boolean | UrlTree>
         | boolean
         | UrlTree {
-        return this.loginService.fetchLoginSettings().pipe(
+        return this.loginSettingsService.getSettings().pipe(
             map(config => {
                 return config.allowSelfRegistration
                     ? true
diff --git 
a/ui/src/app/core/setup/guards/restore-password-allowed.can-activate.guard.ts 
b/ui/src/app/core/setup/guards/restore-password-allowed.can-activate.guard.ts
index e7f51df072..66c1060aef 100644
--- 
a/ui/src/app/core/setup/guards/restore-password-allowed.can-activate.guard.ts
+++ 
b/ui/src/app/core/setup/guards/restore-password-allowed.can-activate.guard.ts
@@ -23,14 +23,14 @@ import {
     RouterStateSnapshot,
     UrlTree,
 } from '@angular/router';
-import { LoginService } from '../../../login/services/login.service';
+import { LoginSettingsService } from 
'../../../login/services/login-settings.service';
 import { Observable } from 'rxjs';
 import { map } from 'rxjs/operators';
 
 @Injectable({ providedIn: 'root' })
 export class RestorePasswordAllowedCanActivateGuard {
     private router = inject(Router);
-    private loginService = inject(LoginService);
+    private loginSettingsService = inject(LoginSettingsService);
 
     canActivate(
         _route: ActivatedRouteSnapshot,
@@ -40,8 +40,8 @@ export class RestorePasswordAllowedCanActivateGuard {
         | Promise<boolean | UrlTree>
         | boolean
         | UrlTree {
-        return this.loginService
-            .fetchLoginSettings()
+        return this.loginSettingsService
+            .getSettings()
             .pipe(
                 map(config =>
                     config.allowPasswordRecovery
diff --git a/ui/src/app/core/setup/guards/terms.can-activate-children.guard.ts 
b/ui/src/app/core/setup/guards/terms.can-activate-children.guard.ts
index 7eaf577d50..deb2e4e2f0 100644
--- a/ui/src/app/core/setup/guards/terms.can-activate-children.guard.ts
+++ b/ui/src/app/core/setup/guards/terms.can-activate-children.guard.ts
@@ -26,7 +26,7 @@ import {
     RouterStateSnapshot,
 } from '@angular/router';
 import { CurrentUserService } from '@streampipes/shared-ui';
-import { LoginService } from '../../../login/services/login.service';
+import { LoginSettingsService } from 
'../../../login/services/login-settings.service';
 import { of, take } from 'rxjs';
 import { catchError, map } from 'rxjs/operators';
 
@@ -37,7 +37,7 @@ export class TermsCanActivateChildrenGuard implements 
CanActivateChild {
         state: RouterStateSnapshot,
     ): MaybeAsync<GuardResult> {
         const currentUser = this.currentUserService.getCurrentUser();
-        return this.loginService.fetchLoginSettings().pipe(
+        return this.loginSettingsService.getSettings().pipe(
             take(1),
             map(settings => {
                 const needsAck =
@@ -56,7 +56,7 @@ export class TermsCanActivateChildrenGuard implements 
CanActivateChild {
     }
 
     private currentUserService = inject(CurrentUserService);
-    private loginService = inject(LoginService);
+    private loginSettingsService = inject(LoginSettingsService);
 
     private router = inject(Router);
 }
diff --git a/ui/src/app/help/help.component.ts 
b/ui/src/app/help/help.component.ts
index f85d009b64..214e696ad6 100644
--- a/ui/src/app/help/help.component.ts
+++ b/ui/src/app/help/help.component.ts
@@ -27,7 +27,7 @@ import {
     LayoutDirective,
 } from '@ngbracket/ngx-layout/flex';
 import { MatTab, MatTabGroup } from '@angular/material/tabs';
-import { LoginService } from '../login/services/login.service';
+import { LoginSettingsService } from 
'../login/services/login-settings.service';
 import { InfoTabComponent } from './components/info/info.component';
 import { DocumentationTabComponent } from 
'./components/documentation/documentation.component';
 import { ShortcutsTabComponent } from 
'./components/shortcuts/shortcuts.component';
@@ -52,7 +52,7 @@ import { TranslatePipe, TranslateService } from 
'@ngx-translate/core';
 })
 export class HelpComponent implements OnInit {
     private breadcrumbService = inject(SpBreadcrumbService);
-    private loginService = inject(LoginService);
+    private loginSettingsService = inject(LoginSettingsService);
     private translateService = inject(TranslateService);
 
     selectedIndex = 0;
@@ -67,7 +67,7 @@ export class HelpComponent implements OnInit {
         this.breadcrumbService.updateBreadcrumb([
             { label: this.translateService.instant('Help') },
         ]);
-        this.loginService.fetchLoginSettings().subscribe(res => {
+        this.loginSettingsService.getSettings().subscribe(res => {
             this.documentationLink = res.linkSettings?.documentationUrl || '';
             this.showDocumentationTab =
                 !!res.linkSettings?.showDocumentationLinkInProfileMenu &&
diff --git a/ui/src/app/login/components/base-login-page.directive.ts 
b/ui/src/app/login/components/base-login-page.directive.ts
index ef15cb926f..87228dbc98 100644
--- a/ui/src/app/login/components/base-login-page.directive.ts
+++ b/ui/src/app/login/components/base-login-page.directive.ts
@@ -18,6 +18,7 @@
 
 import { Directive, inject, OnInit } from '@angular/core';
 import { LoginService } from '../services/login.service';
+import { LoginSettingsService } from '../services/login-settings.service';
 import { LoginModel } from './login/login.model';
 
 @Directive()
@@ -26,9 +27,10 @@ export abstract class BaseLoginPageDirective implements 
OnInit {
     protected configReady = false;
 
     protected loginService = inject(LoginService);
+    protected loginSettingsService = inject(LoginSettingsService);
 
     ngOnInit(): void {
-        this.loginService.fetchLoginSettings().subscribe(result => {
+        this.loginSettingsService.getSettings().subscribe(result => {
             this.loginSettings = result;
             this.configReady = true;
             this.onSettingsAvailable();
diff --git 
a/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts 
b/ui/src/app/login/services/login-settings.service.ts
similarity index 51%
copy from 
ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts
copy to ui/src/app/login/services/login-settings.service.ts
index ccccc288e5..347a74399b 100644
--- a/ui/src/app/core/setup/guards/registration-allowed.can-activate.guard.ts
+++ b/ui/src/app/login/services/login-settings.service.ts
@@ -17,35 +17,31 @@
  */
 
 import { Injectable, inject } from '@angular/core';
-import {
-    ActivatedRouteSnapshot,
-    Router,
-    RouterStateSnapshot,
-    UrlTree,
-} from '@angular/router';
-import { LoginService } from '../../../login/services/login.service';
-import { Observable } from 'rxjs';
-import { map } from 'rxjs/operators';
+import { HttpClient } from '@angular/common/http';
+import { PlatformServicesCommons } from '@streampipes/platform-services';
+import { Observable, shareReplay } from 'rxjs';
+import { LoginModel } from '../components/login/login.model';
 
 @Injectable({ providedIn: 'root' })
-export class RegistrationAllowedCanActivateGuard {
-    private router = inject(Router);
-    private loginService = inject(LoginService);
+export class LoginSettingsService {
+    private http = inject(HttpClient);
+    private platformServicesCommons = inject(PlatformServicesCommons);
 
-    canActivate(
-        _route: ActivatedRouteSnapshot,
-        _state: RouterStateSnapshot,
-    ):
-        | Observable<boolean | UrlTree>
-        | Promise<boolean | UrlTree>
-        | boolean
-        | UrlTree {
-        return this.loginService.fetchLoginSettings().pipe(
-            map(config => {
-                return config.allowSelfRegistration
-                    ? true
-                    : this.router.parseUrl('register');
-            }),
-        );
+    private settings$?: Observable<LoginModel>;
+
+    getSettings(): Observable<LoginModel> {
+        if (!this.settings$) {
+            this.settings$ = this.http
+                .get<LoginModel>(
+                    
`${this.platformServicesCommons.apiBasePath}/auth/settings`,
+                )
+                .pipe(shareReplay(1));
+        }
+
+        return this.settings$;
+    }
+
+    invalidateCache(): void {
+        this.settings$ = undefined;
     }
 }
diff --git a/ui/src/app/login/services/login.service.ts 
b/ui/src/app/login/services/login.service.ts
index d5b17f1df1..95a886acff 100644
--- a/ui/src/app/login/services/login.service.ts
+++ b/ui/src/app/login/services/login.service.ts
@@ -19,8 +19,7 @@
 import { Injectable, inject } from '@angular/core';
 import { HttpClient, HttpContext } from '@angular/common/http';
 import { PlatformServicesCommons } from '@streampipes/platform-services';
-import { Observable, shareReplay } from 'rxjs';
-import { LoginModel } from '../components/login/login.model';
+import { Observable } from 'rxjs';
 import { RegistrationModel } from '../components/register/registration.model';
 import { NGX_LOADING_BAR_IGNORED } from '@ngx-loading-bar/http-client';
 
@@ -29,19 +28,6 @@ export class LoginService {
     private http = inject(HttpClient);
     private platformServicesCommons = inject(PlatformServicesCommons);
 
-    private settings$?: Observable<LoginModel>;
-
-    fetchLoginSettings(): Observable<LoginModel> {
-        if (!this.settings$) {
-            this.settings$ = this.http
-                .get<LoginModel>(
-                    
`${this.platformServicesCommons.apiBasePath}/auth/settings`,
-                )
-                .pipe(shareReplay({ bufferSize: 1, refCount: true }));
-        }
-        return this.settings$;
-    }
-
     login(credentials): Observable<any> {
         return this.http.post(
             this.platformServicesCommons.apiBasePath + '/auth/login',

Reply via email to