Skip to content

Commit

Permalink
122357: Reduced the amount of times the browse observables are fired …
Browse files Browse the repository at this point in the history
…again
  • Loading branch information
alexandrevryghem committed Jan 9, 2025
1 parent 6e29f30 commit 34f35d7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
26 changes: 16 additions & 10 deletions src/app/browse-by/browse-by-date/browse-by-date.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { BrowseByMetadataComponent, browseParamsToOptions, getBrowseSearchOptions } from '../browse-by-metadata/browse-by-metadata.component';
import { BrowseByMetadataComponent, browseParamsToOptions } from '../browse-by-metadata/browse-by-metadata.component';
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { ActivatedRoute, Params, Router, Data } from '@angular/router';
import { BrowseService } from '../../core/browse/browse.service';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
import { PaginationService } from '../../core/pagination/pagination.service';
import { map } from 'rxjs/operators';
import { map, distinctUntilChanged } from 'rxjs/operators';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { isValidDate } from '../../shared/date.util';
Expand Down Expand Up @@ -53,16 +53,22 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
const sortConfig = new SortOptions('default', SortDirection.ASC);
this.startsWithType = StartsWithType.date;
// include the thumbnail configuration in browse search options
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params & Data> = observableCombineLatest([
this.route.queryParams,
this.route.data,
]).pipe(
map(([queryParams, data]: [Params, Data]) => Object.assign({}, queryParams, data)),
distinctUntilChanged((prev, curr) => prev.id === curr.id && prev.startsWith === curr.startsWith),
);
this.subs.push(
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
this.currentPagination$, this.currentSort$]).pipe(
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
return [Object.assign({}, routeParams, queryParams, data), 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 & Data, 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
@@ -1,5 +1,5 @@
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, of as observableOf } from 'rxjs';
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges } from '@angular/core';
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges, SimpleChanges } from '@angular/core';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
Expand Down Expand Up @@ -190,8 +190,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {

}

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

/**
Expand Down
2 changes: 0 additions & 2 deletions src/app/browse-by/browse-by-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowseByGuard } from './browse-by-guard';
import { BrowseByDSOBreadcrumbResolver } from './browse-by-dso-breadcrumb.resolver';
import { BrowseByI18nBreadcrumbResolver } from './browse-by-i18n-breadcrumb.resolver';
import { BrowseByPageComponent } from './browse-by-page/browse-by-page.component';
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';

@NgModule({
imports: [
Expand All @@ -13,7 +12,6 @@ import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
path: '',
resolve: {
breadcrumb: BrowseByDSOBreadcrumbResolver,
menu: DSOEditMenuResolver
},
children: [
{
Expand Down
6 changes: 4 additions & 2 deletions src/app/core/browse/browse.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, shareReplay } from 'rxjs';
import { distinctUntilChanged, map, startWith } from 'rxjs/operators';
import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../shared/empty.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
Expand Down Expand Up @@ -102,7 +102,8 @@ export class BrowseService {
href = new URLCombiner(href, `?${args.join('&')}`).toString();
}
return href;
})
}),
shareReplay(1),
);
if (options.fetchThumbnail ) {
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$, {}, undefined, undefined, ...BROWSE_LINKS_TO_FOLLOW);
Expand Down Expand Up @@ -151,6 +152,7 @@ export class BrowseService {
}
return href;
}),
shareReplay(1),
);
if (options.fetchThumbnail) {
return this.hrefOnlyDataService.findListByHref<Item>(href$, {}, undefined, undefined, ...BROWSE_LINKS_TO_FOLLOW);
Expand Down

0 comments on commit 34f35d7

Please sign in to comment.