From c683ee71abb54cdb0247927354ee6ab17c51e894 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Wed, 6 Sep 2023 20:31:41 +0200 Subject: [PATCH] Adding memory to piper to reduce computation: https://stackoverflow.com/questions/77053367/rxjs-pipe-evaluates-too-often-then-breaks-in-anugular-app --- src/frontend/app/ui/gallery/blog/blog.service.ts | 4 ++-- src/frontend/app/ui/gallery/content.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/app/ui/gallery/blog/blog.service.ts b/src/frontend/app/ui/gallery/blog/blog.service.ts index 5dda6a7f..5b80ac0b 100644 --- a/src/frontend/app/ui/gallery/blog/blog.service.ts +++ b/src/frontend/app/ui/gallery/blog/blog.service.ts @@ -3,7 +3,7 @@ import {NetworkService} from '../../../model/network/network.service'; import {FileDTO} from '../../../../../common/entities/FileDTO'; import {Utils} from '../../../../../common/Utils'; import {ContentService} from '../content.service'; -import {mergeMap, Observable} from 'rxjs'; +import {mergeMap, Observable, shareReplay} from 'rxjs'; import {MDFilesFilterPipe} from '../../../pipes/MDFilesFilterPipe'; @Injectable() @@ -27,7 +27,7 @@ export class BlogService { .map(f => this.splitMarkDown(f, dates)); return (await Promise.all(files)).flat(); - })); + }), shareReplay(1)); } private async splitMarkDown(file: FileDTO, dates: number[]): Promise { diff --git a/src/frontend/app/ui/gallery/content.service.ts b/src/frontend/app/ui/gallery/content.service.ts index d3cf9954..ed1944ee 100644 --- a/src/frontend/app/ui/gallery/content.service.ts +++ b/src/frontend/app/ui/gallery/content.service.ts @@ -1,5 +1,5 @@ import {Injectable} from '@angular/core'; -import {Observable} from 'rxjs'; +import {Observable, shareReplay} from 'rxjs'; import {GallerySortingService, GroupedDirectoryContent} from './navigator/sorting.service'; import {FilterService} from './filter/filter.service'; import {ContentLoaderService} from './contentLoader.service'; @@ -16,7 +16,7 @@ export class ContentService { this.sortedFilteredContent = this.sortingService .applySorting( this.filterService.applyFilters(this.contentLoaderService.originalContent) - ); + ).pipe(shareReplay(1)); }