Skip to content

Commit

Permalink
121561 Reduce the number of browse definition requests on Item pages …
Browse files Browse the repository at this point in the history
…by reusing the navbar request for all browse indexes
  • Loading branch information
Koen Pauwels committed Nov 28, 2024
1 parent 404ccd9 commit 7f12d38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/app/core/shared/browse-definition.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { autoserialize } from 'cerialize';
import { autoserialize, autoserializeAs } from 'cerialize';
import { CacheableObject } from '../cache/cacheable-object.model';

/**
Expand All @@ -9,6 +9,9 @@ export abstract class BrowseDefinition extends CacheableObject {
@autoserialize
id: string;

@autoserializeAs('metadata')
metadataKeys: string[];

/**
* Get the render type of the BrowseDefinition model
*/
Expand Down
3 changes: 0 additions & 3 deletions src/app/core/shared/hierarchical-browse-definition.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export class HierarchicalBrowseDefinition extends BrowseDefinition {
@autoserialize
vocabulary: string;

@autoserializeAs('metadata')
metadataKeys: string[];

get self(): string {
return this._links.self.href;
}
Expand Down
3 changes: 0 additions & 3 deletions src/app/core/shared/non-hierarchical-browse-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export abstract class NonHierarchicalBrowseDefinition extends BrowseDefinition {
@autoserializeAs('order')
defaultSortOrder: string;

@autoserializeAs('metadata')
metadataKeys: string[];

@autoserialize
dataType: BrowseByDataType;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Component, Input } from '@angular/core';
import zip from 'lodash/zip';

Check failure on line 2 in src/app/item-page/simple/field-components/specific-field/item-page-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

'zip' is defined but never used

Check failure on line 2 in src/app/item-page/simple/field-components/specific-field/item-page-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

'zip' is defined but never used
import intersectionWith from 'lodash/intersectionWith';
import { Item } from '../../../../core/shared/item.model';
import { map } from 'rxjs/operators';
import { mergeAll, first, filter } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { BrowseDefinition } from '../../../../core/shared/browse-definition.model';
import { BrowseDefinitionDataService } from '../../../../core/browse/browse-definition-data.service';
import { getRemoteDataPayload } from '../../../../core/shared/operators';
import {
getRemoteDataPayload,
getPaginatedListPayload,
getFirstSucceededRemoteData
} from '../../../../core/shared/operators';
import { BrowseService } from '../../../../core/browse/browse.service';

/**
* This component can be used to represent metadata on a simple item page.
Expand All @@ -17,7 +24,8 @@ import { getRemoteDataPayload } from '../../../../core/shared/operators';
})
export class ItemPageFieldComponent {

constructor(protected browseDefinitionDataService: BrowseDefinitionDataService) {
constructor(protected browseDefinitionDataService: BrowseDefinitionDataService,
protected browseService: BrowseService) {
}

/**
Expand Down Expand Up @@ -56,9 +64,20 @@ export class ItemPageFieldComponent {
* link in dspace.cfg (webui.browse.link.<n>)
*/
get browseDefinition(): Observable<BrowseDefinition> {
return this.browseDefinitionDataService.findByFields(this.fields).pipe(
return this.browseService.getBrowseDefinitions().pipe(
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
map((def) => def)
getPaginatedListPayload(),
mergeAll(),
filter((def: BrowseDefinition) =>
intersectionWith(def.metadataKeys, this.fields, ItemPageFieldComponent.fieldMatch).length > 0
),
first()
);
}

private static fieldMatch(spec: string, field: string): boolean {
return field === spec
|| (spec.endsWith('.*') && field.substring(0, spec.length - 1) === spec.substring(0, spec.length - 1));
}
}

0 comments on commit 7f12d38

Please sign in to comment.