The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf: have more than 1ms granularity for rebuild detection

+12 -10
+12 -10
quartz/build.ts
··· 39 39 type FileEvent = "add" | "change" | "delete" 40 40 41 41 function newBuildId() { 42 - return new Date().toISOString() 42 + return Math.random().toString(36).substring(2, 8) 43 43 } 44 44 45 45 async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) { ··· 162 162 return 163 163 } 164 164 165 - const buildStart = new Date().getTime() 166 - buildData.lastBuildMs = buildStart 165 + const buildId = newBuildId() 166 + ctx.buildId = buildId 167 + buildData.lastBuildMs = new Date().getTime() 167 168 const release = await mut.acquire() 168 - if (buildData.lastBuildMs > buildStart) { 169 + 170 + // if there's another build after us, release and let them do it 171 + if (ctx.buildId !== buildId) { 169 172 release() 170 173 return 171 174 } 172 175 173 176 const perf = new PerfTimer() 174 177 console.log(chalk.yellow("Detected change, rebuilding...")) 175 - ctx.buildId = newBuildId() 176 178 177 179 // UPDATE DEP GRAPH 178 180 const fp = joinSegments(argv.directory, toPosixPath(filepath)) as FilePath ··· 357 359 toRemove.add(filePath) 358 360 } 359 361 360 - const buildStart = new Date().getTime() 361 - buildData.lastBuildMs = buildStart 362 + const buildId = newBuildId() 363 + ctx.buildId = buildId 364 + buildData.lastBuildMs = new Date().getTime() 362 365 const release = await mut.acquire() 363 366 364 367 // there's another build after us, release and let them do it 365 - if (buildData.lastBuildMs > buildStart) { 368 + if (ctx.buildId !== buildId) { 366 369 release() 367 370 return 368 371 } 369 372 370 373 const perf = new PerfTimer() 371 374 console.log(chalk.yellow("Detected change, rebuilding...")) 372 - ctx.buildId = newBuildId() 373 375 374 376 try { 375 377 const filesToRebuild = [...toRebuild].filter((fp) => !toRemove.has(fp)) ··· 405 407 } 406 408 } 407 409 408 - release() 409 410 clientRefresh() 410 411 toRebuild.clear() 411 412 toRemove.clear() 413 + release() 412 414 } 413 415 414 416 export default async (argv: Argv, mut: Mutex, clientRefresh: () => void) => {