Skip to content

Commit

Permalink
refactor(read-through-data-cache): finalize caching before writing to DB
Browse files Browse the repository at this point in the history
This is to ensure that temporary files are cleaned up before a
potentially blocking call to the DB.
  • Loading branch information
djwhitt committed Jul 25, 2024
1 parent f068327 commit 5b6761c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/data/read-through-data-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export class ReadThroughDataCache implements ContiguousDataSource {
if (cacheStream !== undefined) {
const hash = hasher.digest('base64url');

try {
await this.dataStore.finalize(cacheStream, hash);
} catch (error: any) {
this.log.error('Error finalizing data in cache:', {
id,
message: error.message,
stack: error.stack,
});
}

this.log.info('Successfully cached data', { id, hash });
try {
await this.contiguousDataIndex.saveDataContentAttributes({
Expand All @@ -207,16 +217,6 @@ export class ReadThroughDataCache implements ContiguousDataSource {
stack: error.stack,
});
}

try {
await this.dataStore.finalize(cacheStream, hash);
} catch (error: any) {
this.log.error('Error finalizing data in cache:', {
id,
message: error.message,
stack: error.stack,
});
}
}
}
});
Expand Down

0 comments on commit 5b6761c

Please sign in to comment.