Skip to content

Commit

Permalink
Improve error tolerance; prevent over-caching. (#95)
Browse files Browse the repository at this point in the history
* Improve error tolerance; prevent over-caching.

* Update SolrIndexer.ts
  • Loading branch information
demiankatz authored Nov 15, 2021
1 parent 8839e8a commit a43f286
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions api/src/services/Fedora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions api/src/services/MetadataExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ class MetadataExtractor {
* @returns Record mapping field names to values
*/
public extractMetadata(dc: DC): Record<string, Array<string>> {
if (typeof dc.children === "undefined") {
throw new Error("Unexpected failure: childless Dublin Core!");
}
const metadata: Record<string, Array<string>> = {};
dc.children.forEach((field) => {
(dc?.children ?? []).forEach((field) => {
if (typeof metadata[field.name] === "undefined") {
metadata[field.name] = [];
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/services/SolrIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class SolrIndexer {
}

async indexPid(pid: string): Promise<NeedleResponse> {
// Empty out Fedora cache data to be sure we get the latest
// 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);
}
Expand Down

0 comments on commit a43f286

Please sign in to comment.