Fix scanner latency for large uploads
This commit is contained in:
1 parent
304a30c7c2
commit
f3e5386d51
1 file changed
+18
-6
@@ -53,12 +53,27 @@ export async function runFullScan(): Promise<{
|
||||
let unchanged = 0;
|
||||
|
||||
// 3. Find new and changed files
|
||||
const newFiles: ScannedFile[] = [];
|
||||
for (const [relPath, file] of scannedFiles) {
|
||||
const existing = dbPaths.get(relPath);
|
||||
|
||||
if (!existing) {
|
||||
// New file — check stability first
|
||||
newFiles.push(file);
|
||||
} else {
|
||||
unchanged++;
|
||||
dbPaths.delete(relPath);
|
||||
}
|
||||
}
|
||||
|
||||
// Check stability for all new files concurrently (takes max 3 seconds total)
|
||||
const stableResults = await Promise.all(
|
||||
newFiles.map(async (file) => {
|
||||
const isStable = await checkFileStability(file.absolutePath);
|
||||
return { file, isStable };
|
||||
})
|
||||
);
|
||||
|
||||
for (const { file, isStable } of stableResults) {
|
||||
const relPath = file.relativePath;
|
||||
if (!isStable) {
|
||||
console.log(`[Scanner] Skipping unstable file: ${relPath}`);
|
||||
continue;
|
||||
@@ -91,10 +106,6 @@ export async function runFullScan(): Promise<{
|
||||
errors.push(msg);
|
||||
console.error(`[Scanner] ${msg}`);
|
||||
}
|
||||
} else {
|
||||
unchanged++;
|
||||
dbPaths.delete(relPath); // Mark as seen
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Find removed files (remaining in dbPaths = not found on disk)
|
||||
@@ -203,3 +214,4 @@ async function checkFileStability(filePath: string): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user