From b94cfaa03ac3cbd272434050d4392760d0180dbd Mon Sep 17 00:00:00 2001 From: ZQ Date: Mon, 10 Apr 2023 12:25:17 +0800 Subject: [PATCH] Remove nested subscribers (#1184) Inefficient nesting of subscribers in IssueDataTable has introduced unnecessary and very expensive computes to CATcher. Let's - Improve CATcher's efficiency by removing the nesting of subscribers in IssueDataTable.ts --- .../shared/issue-tables/IssuesDataTable.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/app/shared/issue-tables/IssuesDataTable.ts b/src/app/shared/issue-tables/IssuesDataTable.ts index 25aa3e0..e973685 100644 --- a/src/app/shared/issue-tables/IssuesDataTable.ts +++ b/src/app/shared/issue-tables/IssuesDataTable.ts @@ -2,7 +2,7 @@ import { DataSource } from '@angular/cdk/table'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { BehaviorSubject, merge, Observable, Subscription } from 'rxjs'; -import { map, mergeMap } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { Issue } from '../../core/models/issue.model'; import { IssueService } from '../../core/services/issue.service'; import { paginateData } from './issue-paginator'; @@ -49,23 +49,19 @@ export class IssuesDataTable extends DataSource { ]; this.issueService.startPollIssues(); - this.issueSubscription = this.issueService.issues$ + this.issueSubscription = merge(...displayDataChanges) .pipe( - mergeMap(() => { - return merge(...displayDataChanges).pipe( - map(() => { - let data = Object.values(this.issueService.issues$.getValue()).reverse(); - if (this.defaultFilter) { - data = data.filter(this.defaultFilter); - } - data = getSortedData(this.sort, data); - data = this.getFilteredTeamData(data); - data = applySearchFilter(this.filter, this.displayedColumn, this.issueService, data); - data = paginateData(this.paginator, data); + map(() => { + let data = Object.values(this.issueService.issues$.getValue()).reverse(); + if (this.defaultFilter) { + data = data.filter(this.defaultFilter); + } + data = getSortedData(this.sort, data); + data = this.getFilteredTeamData(data); + data = applySearchFilter(this.filter, this.displayedColumn, this.issueService, data); + data = paginateData(this.paginator, data); - return data; - }) - ); + return data; }) ) .subscribe((issues) => {