Skip to content

Commit 0570542

Browse files
122357: Reduced the amount of times the browse observables are fired again
1 parent 6e29f30 commit 0570542

4 files changed

Lines changed: 50 additions & 31 deletions

File tree

src/app/browse-by/browse-by-date/browse-by-date.component.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
2-
import { BrowseByMetadataComponent, browseParamsToOptions, getBrowseSearchOptions } from '../browse-by-metadata/browse-by-metadata.component';
2+
import { BrowseByMetadataComponent, browseParamsToOptions } from '../browse-by-metadata/browse-by-metadata.component';
33
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
44
import { hasValue, isNotEmpty } from '../../shared/empty.util';
55
import { ActivatedRoute, Params, Router } from '@angular/router';
66
import { BrowseService } from '../../core/browse/browse.service';
77
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
88
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
99
import { PaginationService } from '../../core/pagination/pagination.service';
10-
import { map } from 'rxjs/operators';
10+
import { map, distinctUntilChanged } from 'rxjs/operators';
1111
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
1212
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
1313
import { isValidDate } from '../../shared/date.util';
@@ -53,16 +53,22 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
5353
const sortConfig = new SortOptions('default', SortDirection.ASC);
5454
this.startsWithType = StartsWithType.date;
5555
// include the thumbnail configuration in browse search options
56-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
5756
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
5857
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
58+
const routeParams$: Observable<Params> = observableCombineLatest([
59+
this.route.params,
60+
this.route.queryParams,
61+
]).pipe(
62+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
63+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
64+
);
5965
this.subs.push(
60-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
61-
this.currentPagination$, this.currentSort$]).pipe(
62-
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
63-
return [Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort];
64-
})
65-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
66+
observableCombineLatest([
67+
routeParams$,
68+
this.scope$,
69+
this.currentPagination$,
70+
this.currentSort$,
71+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
6672
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
6773
this.browseId = params.id || this.defaultBrowseId;
6874
this.startsWith = +params.startsWith || params.startsWith;

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, of as observableOf } from 'rxjs';
2-
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges } from '@angular/core';
2+
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges, SimpleChanges } from '@angular/core';
33
import { RemoteData } from '../../core/data/remote-data';
44
import { PaginatedList } from '../../core/data/paginated-list.model';
55
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
@@ -14,7 +14,7 @@ import { getFirstSucceededRemoteData } from '../../core/shared/operators';
1414
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
1515
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
1616
import { PaginationService } from '../../core/pagination/pagination.service';
17-
import { map } from 'rxjs/operators';
17+
import { map, distinctUntilChanged } from 'rxjs/operators';
1818
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
1919
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
2020
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
@@ -158,15 +158,22 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
158158
ngOnInit(): void {
159159

160160
const sortConfig = new SortOptions('default', SortDirection.ASC);
161-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig));
162161
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
163162
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
163+
const routeParams$: Observable<Params> = observableCombineLatest([
164+
this.route.params,
165+
this.route.queryParams,
166+
]).pipe(
167+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
168+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
169+
);
164170
this.subs.push(
165-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
166-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
167-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
168-
})
169-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
171+
observableCombineLatest([
172+
routeParams$,
173+
this.scope$,
174+
this.currentPagination$,
175+
this.currentSort$,
176+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
170177
this.browseId = params.id || this.defaultBrowseId;
171178
this.authority = params.authority;
172179

@@ -190,8 +197,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
190197

191198
}
192199

193-
ngOnChanges(): void {
194-
this.scope$.next(this.scope);
200+
ngOnChanges(changes: SimpleChanges): void {
201+
if (hasValue(changes.scope)) {
202+
this.scope$.next(this.scope);
203+
}
195204
}
196205

197206
/**

src/app/browse-by/browse-by-routing.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { BrowseByGuard } from './browse-by-guard';
44
import { BrowseByDSOBreadcrumbResolver } from './browse-by-dso-breadcrumb.resolver';
55
import { BrowseByI18nBreadcrumbResolver } from './browse-by-i18n-breadcrumb.resolver';
66
import { BrowseByPageComponent } from './browse-by-page/browse-by-page.component';
7-
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
87

98
@NgModule({
109
imports: [
@@ -13,7 +12,6 @@ import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
1312
path: '',
1413
resolve: {
1514
breadcrumb: BrowseByDSOBreadcrumbResolver,
16-
menu: DSOEditMenuResolver
1715
},
1816
children: [
1917
{

src/app/browse-by/browse-by-title/browse-by-title.component.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { combineLatest as observableCombineLatest } from 'rxjs';
1+
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
22
import { Component, OnInit } from '@angular/core';
33
import { Params } from '@angular/router';
44
import {
55
BrowseByMetadataComponent,
6-
browseParamsToOptions, getBrowseSearchOptions
6+
browseParamsToOptions,
77
} from '../browse-by-metadata/browse-by-metadata.component';
88
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
9-
import { map } from 'rxjs/operators';
9+
import { map, distinctUntilChanged } from 'rxjs/operators';
1010
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
1111
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
1212
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
@@ -24,16 +24,22 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
2424

2525
ngOnInit(): void {
2626
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
27-
// include the thumbnail configuration in browse search options
28-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
2927
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
3028
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
29+
const routeParams$: Observable<Params> = observableCombineLatest([
30+
this.route.params,
31+
this.route.queryParams,
32+
]).pipe(
33+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
34+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
35+
);
3136
this.subs.push(
32-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
33-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
34-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
35-
})
36-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
37+
observableCombineLatest([
38+
routeParams$,
39+
this.scope$,
40+
this.currentPagination$,
41+
this.currentSort$,
42+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
3743
this.startsWith = +params.startsWith || params.startsWith;
3844
this.browseId = params.id || this.defaultBrowseId;
3945
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);

0 commit comments

Comments
 (0)