From 9d59af1c77193d8b46bbefd83521ddb6c283d953 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Thu, 11 Nov 2021 12:56:05 -0500 Subject: [PATCH 1/2] Improve error tolerance; prevent over-caching. --- api/src/services/Fedora.ts | 4 ++++ api/src/services/MetadataExtractor.ts | 5 +---- api/src/services/SolrIndexer.ts | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/src/services/Fedora.ts b/api/src/services/Fedora.ts index bba176a1..08980257 100644 --- a/api/src/services/Fedora.ts +++ b/api/src/services/Fedora.ts @@ -92,6 +92,10 @@ export class Fedora { return data; } + public clearCache(pid: string): void { + this.cache[pid] = {}; + } + protected getCache(pid: string, key: string): string { if (typeof this.cache[pid] === "undefined" || typeof this.cache[pid][key] === "undefined") { return null; diff --git a/api/src/services/MetadataExtractor.ts b/api/src/services/MetadataExtractor.ts index 5e4668b7..be69fbd9 100644 --- a/api/src/services/MetadataExtractor.ts +++ b/api/src/services/MetadataExtractor.ts @@ -19,11 +19,8 @@ class MetadataExtractor { * @returns Record mapping field names to values */ public extractMetadata(dc: DC): Record> { - if (typeof dc.children === "undefined") { - throw new Error("Unexpected failure: childless Dublin Core!"); - } const metadata: Record> = {}; - dc.children.forEach((field) => { + (dc?.children ?? []).forEach((field) => { if (typeof metadata[field.name] === "undefined") { metadata[field.name] = []; } diff --git a/api/src/services/SolrIndexer.ts b/api/src/services/SolrIndexer.ts index 64e28573..9999b1f3 100644 --- a/api/src/services/SolrIndexer.ts +++ b/api/src/services/SolrIndexer.ts @@ -64,6 +64,9 @@ class SolrIndexer { } async indexPid(pid: string): Promise { + // Empty out Fedora cache data to be sure we get the latest + // information while indexing: + this.hierarchyCollector.fedora.clearCache(pid); const fedoraFields = await this.getFields(pid); return await this.solr.indexRecord(this.config.solrCore, fedoraFields); } From 3679366d250652eb4471cd53566c372981be17c2 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Thu, 11 Nov 2021 13:37:06 -0500 Subject: [PATCH 2/2] Update SolrIndexer.ts --- api/src/services/SolrIndexer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/services/SolrIndexer.ts b/api/src/services/SolrIndexer.ts index 9999b1f3..81ab6bf6 100644 --- a/api/src/services/SolrIndexer.ts +++ b/api/src/services/SolrIndexer.ts @@ -65,7 +65,8 @@ class SolrIndexer { async indexPid(pid: string): Promise { // Empty out Fedora cache data to be sure we get the latest - // information while indexing: + // information while indexing. + // TODO: review datastream caching logic; do we need it? Is there a better way? this.hierarchyCollector.fedora.clearCache(pid); const fedoraFields = await this.getFields(pid); return await this.solr.indexRecord(this.config.solrCore, fedoraFields);