feat(locate-db): implement BFS directory walk for scanning with progress reporting

This commit is contained in:
Jaime Idolpx 2026-06-17 13:08:52 -04:00
parent f66f5f6d77
commit 65cc6bb602

View File

@ -180,12 +180,27 @@ export async function buildLocateDb(
signal?.throwIfAborted();
const sqlite3 = await getSqlite3();
// ── 1. Recursive PROPFIND on /sd ────────────────────────────────────────
const entries = await listDirectory(
'/sd', true,
bytes => onProgress?.('scanning', bytes),
signal,
);
// ── 1. BFS directory walk with Depth:1 per directory ────────────────────
// Depth:infinity is not supported by the device's WebDAV server, so we
// walk the tree manually, one directory at a time.
const entries: Awaited<ReturnType<typeof listDirectory>> = [];
const queue: string[] = ['/sd'];
let totalBytes = 0;
while (queue.length > 0) {
signal?.throwIfAborted();
const dir = queue.shift()!;
let prevBytes = 0;
const batch = await listDirectory(dir, false, bytes => {
totalBytes += bytes - prevBytes;
prevBytes = bytes;
onProgress?.('scanning', totalBytes, dir);
}, signal);
for (const e of batch) {
entries.push(e);
if (e.type === 'folder') queue.push(e.path);
}
}
signal?.throwIfAborted();
// ── 2. Build in-memory DB ───────────────────────────────────────────────