Skip to content

Commit

Permalink
perf: memoise EDM Aggregation displayableWebResources (#2576)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwd authored Feb 11, 2025
1 parent 022c28d commit b6f903a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/portal/src/plugins/europeana/edm/Aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const sortByIsNextInSequence = (source) => {
};

export default class Aggregation extends Base {
#displayableWebResources;

static propertyClasses = {
webResources: WebResource
};
Expand All @@ -76,19 +78,22 @@ export default class Aggregation extends Base {
return (this.webResources || []).filter((wr) => wr.isIIIFPresentationManifest);
}

// TODO: memoise
get displayableWebResources() {
const uris = [].concat(this.hasView || []);
if (!this.#displayableWebResources) {
const uris = [].concat(this.hasView || []);

if (this.edmIsShownBy) {
uris.unshift(this.edmIsShownBy);
} else if (this.edmIsShownAt) {
uris.unshift(this.edmIsShownAt);
}
if (this.edmIsShownBy) {
uris.unshift(this.edmIsShownBy);
} else if (this.edmIsShownAt) {
uris.unshift(this.edmIsShownAt);
}

const wrs = uris.map((uri) => (this.webResources || []).find((wr) => wr.about === uri));
const wrs = uris.map((uri) => (this.webResources || []).find((wr) => wr.about === uri));

// Sort by isNextInSequence property if present
this.#displayableWebResources = sortByIsNextInSequence(wrs);
}

// Sort by isNextInSequence property if present
return sortByIsNextInSequence(wrs);
return this.#displayableWebResources;
}
}

0 comments on commit b6f903a

Please sign in to comment.