upload: optimized disk-space check

Massimo Melina committed Jul 6, 2024 at 19:36 UTC db681c613ddd72d0dcc9448d39c7986ba75a360b
1 file changed +4 -1
src/upload.ts
+4 -1
@@ -60,7 +60,10 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
60 }
61 else
62 try {
63 - const statDir = base.source!
63 + // refer to the source of the closest node that actually belongs to the vfs, so that cache is more effective
64 + let closestVfsNode: typeof base | undefined = base
65 + while (closestVfsNode && !closestVfsNode.original) closestVfsNode = closestVfsNode.parent
66 + const statDir = closestVfsNode!.source!
67 if (!Object.hasOwn(cache, statDir)) {
68 const c = cache[statDir] = getDiskSpaceSync(statDir)
69 if (!c) throw 'miss'