Skip to content

Commit 795f300

Browse files
authored
Merge pull request DSpace#3913 from alexandrevryghem/w2p-122357_browse-performance-fixes_contribute-7_x
[Port dspace-7_x] Browse performance fixes
2 parents 38d5f87 + bb3d2bb commit 795f300

4 files changed

Lines changed: 44 additions & 30 deletions

File tree

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BrowseService } from '../../core/browse/browse.service';
1010
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
1111
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
1212
import { PaginationService } from '../../core/pagination/pagination.service';
13-
import { map, take } from 'rxjs/operators';
13+
import { map, distinctUntilChanged } from 'rxjs/operators';
1414
import { of as observableOf } from 'rxjs';
1515
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
1616
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
@@ -61,16 +61,19 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
6161
this.startsWithType = StartsWithType.date;
6262
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
6363
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
64+
const routeParams$: Observable<Params> = observableCombineLatest([
65+
this.route.params,
66+
this.route.queryParams,
67+
]).pipe(
68+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
69+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
70+
);
6471
this.subs.push(
65-
observableCombineLatest(
66-
[ this.route.params.pipe(take(1)),
67-
this.route.queryParams,
68-
this.currentPagination$,
69-
this.currentSort$]).pipe(
70-
map(([routeParams, queryParams, currentPage, currentSort]) => {
71-
return [Object.assign({}, routeParams, queryParams), currentPage, currentSort];
72-
})
73-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
72+
observableCombineLatest([
73+
routeParams$,
74+
this.currentPagination$,
75+
this.currentSort$,
76+
]).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
7477
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
7578
this.browseId = params.id || this.defaultBrowseId;
7679
this.startsWith = +params.startsWith || params.startsWith;

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
1515
import { DSpaceObject } from '../../core/shared/dspace-object.model';
1616
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
1717
import { PaginationService } from '../../core/pagination/pagination.service';
18-
import { filter, map, mergeMap, take } from 'rxjs/operators';
18+
import { filter, map, mergeMap, distinctUntilChanged } from 'rxjs/operators';
1919
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
2020
import { Bitstream } from '../../core/shared/bitstream.model';
2121
import { Collection } from '../../core/shared/collection.model';
@@ -162,20 +162,22 @@ export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
162162
return;
163163
}
164164
const sortConfig = new SortOptions('default', SortDirection.ASC);
165-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig));
166165
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
167166
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
167+
const routeParams$: Observable<Params> = observableCombineLatest([
168+
this.route.params,
169+
this.route.queryParams,
170+
]).pipe(
171+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
172+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
173+
);
168174
this.subs.push(
169-
observableCombineLatest(
170-
[ this.route.params.pipe(take(1)),
171-
this.route.queryParams,
172-
this.currentPagination$,
173-
this.currentSort$]).pipe(
174-
map(([routeParams, queryParams, currentPage, currentSort]) => {
175-
return [Object.assign({}, routeParams, queryParams),currentPage,currentSort];
176-
})
177-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
178-
this.browseId = params.id || this.defaultBrowseId;
175+
observableCombineLatest([
176+
routeParams$,
177+
this.currentPagination$,
178+
this.currentSort$,
179+
]).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
180+
this.browseId = params.id || this.defaultBrowseId;
179181
this.authority = params.authority;
180182

181183
if (typeof params.value === 'string'){

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { combineLatest as observableCombineLatest } from 'rxjs';
1+
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
22
import { Component, Inject, PLATFORM_ID } from '@angular/core';
33
import { ActivatedRoute, Params, Router } from '@angular/router';
44
import { hasValue } from '../../shared/empty.util';
@@ -10,7 +10,7 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
1010
import { BrowseService } from '../../core/browse/browse.service';
1111
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
1212
import { PaginationService } from '../../core/pagination/pagination.service';
13-
import { map, take } from 'rxjs/operators';
13+
import { map, distinctUntilChanged } from 'rxjs/operators';
1414
import { of as observableOf } from 'rxjs';
1515
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
1616
import { AppConfig, APP_CONFIG } from '../../../config/app-config.interface';
@@ -48,12 +48,19 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
4848
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
4949
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
5050
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
51+
const routeParams$: Observable<Params> = observableCombineLatest([
52+
this.route.params,
53+
this.route.queryParams,
54+
]).pipe(
55+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
56+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
57+
);
5158
this.subs.push(
52-
observableCombineLatest([this.route.params.pipe(take(1)), this.route.queryParams, this.currentPagination$, this.currentSort$]).pipe(
53-
map(([routeParams, queryParams, currentPage, currentSort]) => {
54-
return [Object.assign({}, routeParams, queryParams),currentPage,currentSort];
55-
})
56-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
59+
observableCombineLatest([
60+
routeParams$,
61+
this.currentPagination$,
62+
this.currentSort$,
63+
]).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
5764
this.startsWith = +params.startsWith || params.startsWith;
5865
this.browseId = params.id || this.defaultBrowseId;
5966
this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);

src/app/core/data/base/base-data.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* http://www.dspace.org/license/
77
*/
88

9-
import { AsyncSubject, from as observableFrom, Observable, of as observableOf } from 'rxjs';
9+
import { AsyncSubject, from as observableFrom, Observable, of as observableOf, shareReplay } from 'rxjs';
1010
import { map, mergeMap, skipWhile, switchMap, take, tap, toArray } from 'rxjs/operators';
1111
import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../../shared/empty.util';
1212
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
@@ -264,6 +264,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
264264
isNotEmptyOperator(),
265265
take(1),
266266
map((href: string) => this.buildHrefFromFindOptions(href, {}, [], ...linksToFollow)),
267+
shareReplay(1),
267268
);
268269

269270
const startTime: number = new Date().getTime();
@@ -299,6 +300,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
299300
isNotEmptyOperator(),
300301
take(1),
301302
map((href: string) => this.buildHrefFromFindOptions(href, options, [], ...linksToFollow)),
303+
shareReplay(1),
302304
);
303305

304306
const startTime: number = new Date().getTime();

0 commit comments

Comments
 (0)