Skip to content

Commit 339aa42

Browse files
committed
fix(cache): only timestamp if the file has actually changed in the last 30 seconds
1 parent 01240b9 commit 339aa42

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/workers/cache-grouped-scripts-worker.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { formatChoices } from '../core/utils.js'
66
import { parentPort } from 'node:worker_threads'
77
import { type Stamp, getScriptsDb, getTimestamps } from '../core/db.js'
88
import { scriptsSort } from '../core/utils.js'
9+
import { stat } from 'node:fs/promises'
910

1011
// --------------------
1112
// Logging to Parent
@@ -46,6 +47,13 @@ const updateTimestampsDb = async (stamp: Stamp) => {
4647
return null
4748
}
4849

50+
// Get file stats. Make sure it has changed in the last 30 seconds
51+
const fileStats = await stat(stamp.filePath)
52+
if (fileStats.mtime.getTime() < Date.now() - 30000) {
53+
logToParent(`File has not changed in the last 30 seconds: ${stamp.filePath}`)
54+
return null
55+
}
56+
4957
const originalFilePath = stamp.filePath
5058
const timestampsDb = await getTimestamps()
5159
const index = timestampsDb.stamps.findIndex((s) => s.filePath === originalFilePath)

0 commit comments

Comments
 (0)