Skip to content

Commit

Permalink
perf(js_run_devserver): delete files in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Nov 9, 2024
1 parent f7918d4 commit 19f231f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions js/private/js_run_devserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function syncRecursive(src, dst, sandbox, writePerm) {
async function deleteFiles(previousFiles, updatedFiles, sandbox) {
const startTime = perf_hooks.performance.now()

let totalDeleted = 0
const deletions = []

// Remove files that were previously synced but are no longer in the updated list of files to sync
const updatedFilesSet = new Set(updatedFiles)
Expand Down Expand Up @@ -279,18 +279,22 @@ async function deleteFiles(previousFiles, updatedFiles, sandbox) {
mkdirs.clear()

const rmPath = path.join(sandbox, f)
try {
fs.rmSync(rmPath, { recursive: true, force: true })
} catch (e) {
console.error(
`An error has occurred while deleting the synced file ${rmPath}. Error: ${e}`
)
}
totalDeleted++
deletions.push(
fs.promises
.rm(rmPath, { recursive: true, force: true })
.catch((e) =>
console.error(
`An error has occurred while deleting the synced file ${rmPath}. Error: ${e}`
)
)
)
}

await Promise.all(deletions)

var endTime = perf_hooks.performance.now()

const totalDeleted = deletions.length
if (totalDeleted > 0) {
console.error(
`${totalDeleted} file${totalDeleted > 1 ? 's' : ''}/folder${
Expand Down

0 comments on commit 19f231f

Please sign in to comment.