fix: prevent double-counting orphaned pages in conflicting scenarios

This commit is contained in:
meels
2026-07-28 13:17:51 +02:00
parent 80ef971d1a
commit 7958d225d5
2 changed files with 19 additions and 3 deletions

View File

@@ -49,10 +49,15 @@ function derivePipeline({ rawFiles, sourcePages }) {
else unprocessed.push(file);
}
// One pass over sourcePages, so a page appears in `orphaned` at most once no
// matter how many of the three reasons apply to it. Concatenating a separate
// duplicates array here would double-count a losing claimant whose shared raw
// path is also missing from disk.
const rawPaths = new Set(rawFiles.map((f) => f.path));
const orphaned = sourcePages
.filter((p) => !p.rawPath || !rawPaths.has(p.rawPath))
.concat(duplicates);
const duplicateSet = new Set(duplicates);
const orphaned = sourcePages.filter(
(p) => duplicateSet.has(p) || !p.rawPath || !rawPaths.has(p.rawPath)
);
unprocessed.sort((a, b) => a.name.localeCompare(b.name));
processed.sort((a, b) => b.page.name.localeCompare(a.page.name));