Skip to content

Commit df3e00f

Browse files
authored
Merge pull request #3914 from alexandrevryghem/w2p-122357_browse-performance-fixes_contribute-8_x
[Port dspace-8_x] Browse performance fixes
2 parents 47159fe + da9d848 commit df3e00f

File tree

4 files changed

+57
-81
lines changed

4 files changed

+57
-81
lines changed

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

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
of as observableOf,
2323
} from 'rxjs';
2424
import {
25+
distinctUntilChanged,
2526
map,
26-
take,
2727
} from 'rxjs/operators';
2828
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
2929

@@ -42,21 +42,14 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
4242
import { RemoteData } from '../../core/data/remote-data';
4343
import { PaginationService } from '../../core/pagination/pagination.service';
4444
import { Item } from '../../core/shared/item.model';
45-
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
46-
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
47-
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
48-
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
49-
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
5045
import { isValidDate } from '../../shared/date.util';
51-
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
5246
import {
5347
hasValue,
5448
isNotEmpty,
5549
} from '../../shared/empty.util';
5650
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
5751
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
5852
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
59-
import { VarDirective } from '../../shared/utils/var.directive';
6053
import {
6154
BrowseByMetadataComponent,
6255
browseParamsToOptions,
@@ -68,15 +61,8 @@ import {
6861
templateUrl: '../browse-by-metadata/browse-by-metadata.component.html',
6962
standalone: true,
7063
imports: [
71-
VarDirective,
7264
AsyncPipe,
73-
ComcolPageHeaderComponent,
74-
ComcolPageLogoComponent,
7565
NgIf,
76-
ThemedComcolPageHandleComponent,
77-
ThemedComcolPageContentComponent,
78-
DsoEditMenuComponent,
79-
ThemedComcolPageBrowseByComponent,
8066
TranslateModule,
8167
ThemedLoadingComponent,
8268
ThemedBrowseByComponent,
@@ -117,18 +103,20 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
117103
this.startsWithType = StartsWithType.date;
118104
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
119105
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
106+
const routeParams$: Observable<Params> = observableCombineLatest([
107+
this.route.params,
108+
this.route.queryParams,
109+
]).pipe(
110+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
111+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
112+
);
120113
this.subs.push(
121-
observableCombineLatest(
122-
[ this.route.params.pipe(take(1)),
123-
this.route.queryParams,
124-
this.scope$,
125-
this.currentPagination$,
126-
this.currentSort$,
127-
]).pipe(
128-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
129-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
130-
}),
131-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
114+
observableCombineLatest([
115+
routeParams$,
116+
this.scope$,
117+
this.currentPagination$,
118+
this.currentSort$,
119+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
132120
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
133121
this.browseId = params.id || this.defaultBrowseId;
134122
this.startsWith = +params.startsWith || params.startsWith;

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
OnDestroy,
1212
OnInit,
1313
PLATFORM_ID,
14+
SimpleChanges,
1415
} from '@angular/core';
1516
import {
1617
ActivatedRoute,
@@ -26,8 +27,8 @@ import {
2627
Subscription,
2728
} from 'rxjs';
2829
import {
30+
distinctUntilChanged,
2931
map,
30-
take,
3132
} from 'rxjs/operators';
3233
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
3334

@@ -51,20 +52,13 @@ import { BrowseEntry } from '../../core/shared/browse-entry.model';
5152
import { Context } from '../../core/shared/context.model';
5253
import { Item } from '../../core/shared/item.model';
5354
import { getFirstSucceededRemoteData } from '../../core/shared/operators';
54-
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
55-
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
56-
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
57-
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
58-
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
59-
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
6055
import {
6156
hasValue,
6257
isNotEmpty,
6358
} from '../../shared/empty.util';
6459
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
6560
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
6661
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
67-
import { VarDirective } from '../../shared/utils/var.directive';
6862
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
6963

7064
export const BBM_PAGINATION_ID = 'bbm';
@@ -74,15 +68,8 @@ export const BBM_PAGINATION_ID = 'bbm';
7468
styleUrls: ['./browse-by-metadata.component.scss'],
7569
templateUrl: './browse-by-metadata.component.html',
7670
imports: [
77-
VarDirective,
7871
AsyncPipe,
79-
ComcolPageHeaderComponent,
80-
ComcolPageLogoComponent,
8172
NgIf,
82-
ThemedComcolPageHandleComponent,
83-
ThemedComcolPageContentComponent,
84-
DsoEditMenuComponent,
85-
ThemedComcolPageBrowseByComponent,
8673
TranslateModule,
8774
ThemedLoadingComponent,
8875
ThemedBrowseByComponent,
@@ -232,21 +219,22 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
232219
return;
233220
}
234221
const sortConfig = new SortOptions('default', SortDirection.ASC);
235-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig));
236222
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
237223
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
224+
const routeParams$: Observable<Params> = observableCombineLatest([
225+
this.route.params,
226+
this.route.queryParams,
227+
]).pipe(
228+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
229+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
230+
);
238231
this.subs.push(
239-
observableCombineLatest(
240-
[ this.route.params.pipe(take(1)),
241-
this.route.queryParams,
242-
this.scope$,
243-
this.currentPagination$,
244-
this.currentSort$,
245-
]).pipe(
246-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
247-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
248-
}),
249-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
232+
observableCombineLatest([
233+
routeParams$,
234+
this.scope$,
235+
this.currentPagination$,
236+
this.currentSort$,
237+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
250238
this.browseId = params.id || this.defaultBrowseId;
251239
this.authority = params.authority;
252240

@@ -274,8 +262,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
274262

275263
}
276264

277-
ngOnChanges(): void {
278-
this.scope$.next(this.scope);
265+
ngOnChanges(changes: SimpleChanges): void {
266+
if (hasValue(changes.scope)) {
267+
this.scope$.next(this.scope);
268+
}
279269
}
280270

281271
/**

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

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import { Params } from '@angular/router';
1111
import { TranslateModule } from '@ngx-translate/core';
1212
import {
1313
combineLatest as observableCombineLatest,
14+
Observable,
1415
of as observableOf,
1516
} from 'rxjs';
1617
import {
18+
distinctUntilChanged,
1719
map,
18-
take,
1920
} from 'rxjs/operators';
2021

2122
import { environment } from '../../../environments/environment';
@@ -24,15 +25,8 @@ import {
2425
SortOptions,
2526
} from '../../core/cache/models/sort-options.model';
2627
import { ThemedBrowseByComponent } from '../../shared/browse-by/themed-browse-by.component';
27-
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
28-
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
29-
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
30-
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
31-
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
32-
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
3328
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
3429
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
35-
import { VarDirective } from '../../shared/utils/var.directive';
3630
import {
3731
BrowseByMetadataComponent,
3832
browseParamsToOptions,
@@ -44,15 +38,8 @@ import {
4438
templateUrl: '../browse-by-metadata/browse-by-metadata.component.html',
4539
standalone: true,
4640
imports: [
47-
VarDirective,
4841
AsyncPipe,
49-
ComcolPageHeaderComponent,
50-
ComcolPageLogoComponent,
5142
NgIf,
52-
ThemedComcolPageHandleComponent,
53-
ThemedComcolPageContentComponent,
54-
DsoEditMenuComponent,
55-
ThemedComcolPageBrowseByComponent,
5643
TranslateModule,
5744
ThemedLoadingComponent,
5845
ThemedBrowseByComponent,
@@ -71,18 +58,20 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
7158
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
7259
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
7360
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
61+
const routeParams$: Observable<Params> = observableCombineLatest([
62+
this.route.params,
63+
this.route.queryParams,
64+
]).pipe(
65+
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
66+
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
67+
);
7468
this.subs.push(
75-
observableCombineLatest(
76-
[ this.route.params.pipe(take(1)),
77-
this.route.queryParams,
78-
this.scope$,
79-
this.currentPagination$,
80-
this.currentSort$,
81-
]).pipe(
82-
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
83-
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
84-
}),
85-
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
69+
observableCombineLatest([
70+
routeParams$,
71+
this.scope$,
72+
this.currentPagination$,
73+
this.currentSort$,
74+
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
8675
this.startsWith = +params.startsWith || params.startsWith;
8776
this.browseId = params.id || this.defaultBrowseId;
8877
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
from as observableFrom,
1212
Observable,
1313
of as observableOf,
14+
shareReplay,
1415
} from 'rxjs';
1516
import {
1617
map,
@@ -283,6 +284,10 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
283284
isNotEmptyOperator(),
284285
take(1),
285286
map((href: string) => this.buildHrefFromFindOptions(href, {}, [], ...linksToFollow)),
287+
shareReplay({
288+
bufferSize: 1,
289+
refCount: true,
290+
}),
286291
);
287292

288293
const startTime: number = new Date().getTime();
@@ -337,6 +342,10 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
337342
isNotEmptyOperator(),
338343
take(1),
339344
map((href: string) => this.buildHrefFromFindOptions(href, options, [], ...linksToFollow)),
345+
shareReplay({
346+
bufferSize: 1,
347+
refCount: true,
348+
}),
340349
);
341350

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

0 commit comments

Comments
 (0)