From 15fb19ad2f94577ece2649d3eacf9c59fa8e6761 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 4 Jun 2021 14:26:18 +0200 Subject: [PATCH] Limit pushing of filter updates in filter service Limits the pushing updateFilteredData in the baseFilterList service to only listen for actual changes of the list input data This should decrease client stress on autoupdates --- .../ui-services/base-filter-list.service.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/client/src/app/core/ui-services/base-filter-list.service.ts b/client/src/app/core/ui-services/base-filter-list.service.ts index 3c86963be..7cb374031 100644 --- a/client/src/app/core/ui-services/base-filter-list.service.ts +++ b/client/src/app/core/ui-services/base-filter-list.service.ts @@ -1,4 +1,5 @@ import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { distinctUntilChanged } from 'rxjs/operators'; import { BaseModel } from 'app/shared/models/base/base-model'; import { BaseRepository } from '../repositories/base-repository'; @@ -182,10 +183,23 @@ export abstract class BaseFilterListService { this.inputDataSubscription.unsubscribe(); this.inputDataSubscription = null; } - this.inputDataSubscription = inputData.subscribe(data => { - this.inputData = data; - this.updateFilteredData(); - }); + this.inputDataSubscription = inputData + /** + * Every autoupdate pushes data here. + * Not entirely sure why this happens. + * However, we are only concerned about changes to our + * current moddels, so compare the changes should + * limit the updating of filters + */ + .pipe( + distinctUntilChanged((curr, prev) => { + return curr.length === prev.length && curr.every((v, i) => v === prev[i]); + }) + ) + .subscribe(data => { + this.inputData = data; + this.updateFilteredData(); + }); } /**