Skip to content

Commit

Permalink
perf(cache): remove unnecessary file exists checks
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Apr 29, 2024
1 parent 452b986 commit 698ced1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/services/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export const getCacheStats = async (filename: string, settings: Settings) => {
export const getHashOf = async (filename: string, settings: Settings) => {
const hashesFilename = path.resolve(settings.cacheFolder, '__hashes.json')

if (!(await fileExists(hashesFilename))) {
return undefined
}

try {
const hashes = JSON.parse(await fs.readFile(hashesFilename, { encoding: 'utf-8' })) as Record<string, string>
return hashes[filename]
Expand All @@ -64,11 +60,9 @@ export const saveHashOf = async (filename: string, hash: string, settings: Setti

let hashes: Record<string, string> = {}

if (await fileExists(hashesFilename)) {
try {
hashes = JSON.parse(await fs.readFile(hashesFilename, { encoding: 'utf-8' })) as Record<string, string>
} catch (e: unknown) {}
}
try {
hashes = JSON.parse(await fs.readFile(hashesFilename, { encoding: 'utf-8' })) as Record<string, string>
} catch (e: unknown) {}

hashes[filename] = hash

Expand Down

0 comments on commit 698ced1

Please sign in to comment.