Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browse performance fixes #3846

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions src/app/browse-by/browse-by-date/browse-by-date.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
Observable,
} from 'rxjs';
import {
distinctUntilChanged,
map,
take,
} from 'rxjs/operators';
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';

Expand All @@ -38,21 +38,14 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
import { RemoteData } from '../../core/data/remote-data';
import { PaginationService } from '../../core/pagination/pagination.service';
import { Item } from '../../core/shared/item.model';
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
import { isValidDate } from '../../shared/date.util';
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
import {
hasValue,
isNotEmpty,
} from '../../shared/empty.util';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
import { VarDirective } from '../../shared/utils/var.directive';
import {
BrowseByMetadataComponent,
browseParamsToOptions,
Expand All @@ -64,15 +57,8 @@ import {
templateUrl: '../browse-by-metadata/browse-by-metadata.component.html',
standalone: true,
imports: [
VarDirective,
AsyncPipe,
ComcolPageHeaderComponent,
ComcolPageLogoComponent,
NgIf,
ThemedComcolPageHandleComponent,
ThemedComcolPageContentComponent,
DsoEditMenuComponent,
ThemedComcolPageBrowseByComponent,
TranslateModule,
ThemedLoadingComponent,
ThemedBrowseByComponent,
Expand Down Expand Up @@ -108,18 +94,20 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
this.startsWithType = StartsWithType.date;
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
);
this.subs.push(
observableCombineLatest(
[ this.route.params.pipe(take(1)),
this.route.queryParams,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).pipe(
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
}),
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
this.browseId = params.id || this.defaultBrowseId;
this.startsWith = +params.startsWith || params.startsWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
OnChanges,
OnDestroy,
OnInit,
SimpleChanges,
} from '@angular/core';
import {
ActivatedRoute,
Expand All @@ -24,8 +25,8 @@
Subscription,
} from 'rxjs';
import {
distinctUntilChanged,
map,
take,
} from 'rxjs/operators';
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';

Expand All @@ -48,20 +49,13 @@
import { Context } from '../../core/shared/context.model';
import { Item } from '../../core/shared/item.model';
import { getFirstSucceededRemoteData } from '../../core/shared/operators';
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
import {
hasValue,
isNotEmpty,
} from '../../shared/empty.util';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
import { VarDirective } from '../../shared/utils/var.directive';
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';

export const BBM_PAGINATION_ID = 'bbm';
Expand All @@ -71,15 +65,8 @@
styleUrls: ['./browse-by-metadata.component.scss'],
templateUrl: './browse-by-metadata.component.html',
imports: [
VarDirective,
AsyncPipe,
ComcolPageHeaderComponent,
ComcolPageLogoComponent,
NgIf,
ThemedComcolPageHandleComponent,
ThemedComcolPageContentComponent,
DsoEditMenuComponent,
ThemedComcolPageBrowseByComponent,
TranslateModule,
ThemedLoadingComponent,
ThemedBrowseByComponent,
Expand Down Expand Up @@ -215,21 +202,22 @@
ngOnInit(): void {

const sortConfig = new SortOptions('default', SortDirection.ASC);
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig));
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
);
this.subs.push(
observableCombineLatest(
[ this.route.params.pipe(take(1)),
this.route.queryParams,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).pipe(
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
}),
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
this.browseId = params.id || this.defaultBrowseId;
this.authority = params.authority;

Expand Down Expand Up @@ -257,8 +245,10 @@

}

ngOnChanges(): void {
this.scope$.next(this.scope);
ngOnChanges(changes: SimpleChanges): void {
if (hasValue(changes.scope)) {
this.scope$.next(this.scope);

Check warning on line 250 in src/app/browse-by/browse-by-metadata/browse-by-metadata.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L250 was not covered by tests
}
}

/**
Expand Down
45 changes: 18 additions & 27 deletions src/app/browse-by/browse-by-title/browse-by-title.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@ import {
} from '@angular/core';
import { Params } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { combineLatest as observableCombineLatest } from 'rxjs';
import {
combineLatest as observableCombineLatest,
Observable,
} from 'rxjs';
import {
distinctUntilChanged,
map,
take,
} from 'rxjs/operators';

import {
SortDirection,
SortOptions,
} from '../../core/cache/models/sort-options.model';
import { ThemedBrowseByComponent } from '../../shared/browse-by/themed-browse-by.component';
import { ThemedComcolPageBrowseByComponent } from '../../shared/comcol/comcol-page-browse-by/themed-comcol-page-browse-by.component';
import { ThemedComcolPageContentComponent } from '../../shared/comcol/comcol-page-content/themed-comcol-page-content.component';
import { ThemedComcolPageHandleComponent } from '../../shared/comcol/comcol-page-handle/themed-comcol-page-handle.component';
import { ComcolPageHeaderComponent } from '../../shared/comcol/comcol-page-header/comcol-page-header.component';
import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component';
import { DsoEditMenuComponent } from '../../shared/dso-page/dso-edit-menu/dso-edit-menu.component';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { VarDirective } from '../../shared/utils/var.directive';
import {
BrowseByMetadataComponent,
browseParamsToOptions,
Expand All @@ -39,15 +35,8 @@ import {
templateUrl: '../browse-by-metadata/browse-by-metadata.component.html',
standalone: true,
imports: [
VarDirective,
AsyncPipe,
ComcolPageHeaderComponent,
ComcolPageLogoComponent,
NgIf,
ThemedComcolPageHandleComponent,
ThemedComcolPageContentComponent,
DsoEditMenuComponent,
ThemedComcolPageBrowseByComponent,
TranslateModule,
ThemedLoadingComponent,
ThemedBrowseByComponent,
Expand All @@ -62,18 +51,20 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
);
this.subs.push(
observableCombineLatest(
[ this.route.params.pipe(take(1)),
this.route.queryParams,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).pipe(
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
}),
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
this.startsWith = +params.startsWith || params.startsWith;
this.browseId = params.id || this.defaultBrowseId;
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);
Expand Down
9 changes: 9 additions & 0 deletions src/app/core/data/base/base-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
from as observableFrom,
Observable,
of as observableOf,
shareReplay,
} from 'rxjs';
import {
map,
Expand Down Expand Up @@ -288,6 +289,10 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
isNotEmptyOperator(),
take(1),
map((href: string) => this.buildHrefFromFindOptions(href, {}, [], ...linksToFollow)),
shareReplay({
bufferSize: 1,
refCount: true,
}),
);

const startTime: number = new Date().getTime();
Expand Down Expand Up @@ -343,6 +348,10 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
isNotEmptyOperator(),
take(1),
map((href: string) => this.buildHrefFromFindOptions(href, options, [], ...linksToFollow)),
shareReplay({
bufferSize: 1,
refCount: true,
}),
);

const startTime: number = new Date().getTime();
Expand Down
Loading