feat(locate-db): implement BFS directory walk for scanning with progress reporting
This commit is contained in:
parent
f66f5f6d77
commit
65cc6bb602
|
|
@ -180,12 +180,27 @@ export async function buildLocateDb(
|
||||||
signal?.throwIfAborted();
|
signal?.throwIfAborted();
|
||||||
const sqlite3 = await getSqlite3();
|
const sqlite3 = await getSqlite3();
|
||||||
|
|
||||||
// ── 1. Recursive PROPFIND on /sd ────────────────────────────────────────
|
// ── 1. BFS directory walk with Depth:1 per directory ────────────────────
|
||||||
const entries = await listDirectory(
|
// Depth:infinity is not supported by the device's WebDAV server, so we
|
||||||
'/sd', true,
|
// walk the tree manually, one directory at a time.
|
||||||
bytes => onProgress?.('scanning', bytes),
|
const entries: Awaited<ReturnType<typeof listDirectory>> = [];
|
||||||
signal,
|
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();
|
signal?.throwIfAborted();
|
||||||
|
|
||||||
// ── 2. Build in-memory DB ───────────────────────────────────────────────
|
// ── 2. Build in-memory DB ───────────────────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user