Skip to content

Commit a43f286

Browse files
authored
Improve error tolerance; prevent over-caching. (#95)
* Improve error tolerance; prevent over-caching. * Update SolrIndexer.ts
1 parent 8839e8a commit a43f286

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

api/src/services/Fedora.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export class Fedora {
9292
return data;
9393
}
9494

95+
public clearCache(pid: string): void {
96+
this.cache[pid] = {};
97+
}
98+
9599
protected getCache(pid: string, key: string): string {
96100
if (typeof this.cache[pid] === "undefined" || typeof this.cache[pid][key] === "undefined") {
97101
return null;

api/src/services/MetadataExtractor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ class MetadataExtractor {
1919
* @returns Record mapping field names to values
2020
*/
2121
public extractMetadata(dc: DC): Record<string, Array<string>> {
22-
if (typeof dc.children === "undefined") {
23-
throw new Error("Unexpected failure: childless Dublin Core!");
24-
}
2522
const metadata: Record<string, Array<string>> = {};
26-
dc.children.forEach((field) => {
23+
(dc?.children ?? []).forEach((field) => {
2724
if (typeof metadata[field.name] === "undefined") {
2825
metadata[field.name] = [];
2926
}

api/src/services/SolrIndexer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class SolrIndexer {
6464
}
6565

6666
async indexPid(pid: string): Promise<NeedleResponse> {
67+
// Empty out Fedora cache data to be sure we get the latest
68+
// information while indexing.
69+
// TODO: review datastream caching logic; do we need it? Is there a better way?
70+
this.hierarchyCollector.fedora.clearCache(pid);
6771
const fedoraFields = await this.getFields(pid);
6872
return await this.solr.indexRecord(this.config.solrCore, fedoraFields);
6973
}

0 commit comments

Comments
 (0)