fix: isolate failing project analysis batches

This commit is contained in:
muena
2026-10-19 08:50:49 +02:00
parent c50766a0ee
commit e783c67af0
3 changed files with 173 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ import {
canonicalPerson, filenameScanText, groupReviewHits, makeTextBatches, mappingForSelection, mergePeople, spansBySegment,
withoutPlaceholderHits, withoutWhitelistedHits, withoutWhitelistedRules,
} from "./lib/project-review";
import { analyzeProjectBatch } from "./lib/project-analysis";
const run = promisify(execFile);
const MAX_REVIEW_HITS = 50000;
@@ -144,12 +145,15 @@ async function prepare(root: string, files: ProjectFile[], rules: ProjectRule[],
const batches = makeTextBatches([...texts].map(([key, text]) => ({ key, text })));
for (const [index, batch] of batches.entries()) {
onProgress(`Textdateien analysieren: Paket ${index + 1}/${batches.length}`);
const result = await pseudonymize(batch.text, mapping, entityTypes, masks);
mapping = result.mapping;
const byFile = spansBySegment(batch, result.spans);
for (const segment of batch.segments) {
const draft = draftsByPath.get(segment.key)!;
addHits(draft, contentHits(draft.file, byFile.get(segment.key) ?? [], segment.text));
const analyzed = await analyzeProjectBatch(batch, mapping, entityTypes, masks, pseudonymize,
"Textdateien analysieren");
mapping = analyzed.mapping;
for (const { batch: part, result } of analyzed.results) {
const byFile = spansBySegment(part, result.spans);
for (const segment of part.segments) {
const draft = draftsByPath.get(segment.key)!;
addHits(draft, contentHits(draft.file, byFile.get(segment.key) ?? [], segment.text));
}
}
}
const documents = drafts.filter((draft) => draft.file.kind === "document");
@@ -185,19 +189,22 @@ async function prepare(root: string, files: ProjectFile[], rules: ProjectRule[],
const byPath = new Map(paths.map((path) => [path.key, path]));
for (const [index, batch] of pathBatches.entries()) {
onProgress(`Dateinamen analysieren: Paket ${index + 1}/${pathBatches.length}`);
const result = await pseudonymize(batch.text, mapping, entityTypes, masks);
mapping = result.mapping;
const spans = spansBySegment(batch, result.spans);
for (const segment of batch.segments) {
const path = byPath.get(segment.key)!;
const found = toUtf16Offsets(segment.text, spans.get(path.key) ?? []).map((span, hitIndex) => ({
...span, id: `${path.key}:path:${hitIndex}`, file: path.key,
source: "Datei- oder Ordnername", kind: "path" as const,
context: path.value,
}));
path.hits = withoutWhitelistedHits(withoutPlaceholderHits(found, previousPlaceholders), whitelist);
hits.push(...path.hits);
if (hits.length > MAX_REVIEW_HITS) throw new Error("Zu viele Treffer. Bitte weniger Kategorien auswählen.");
const analyzed = await analyzeProjectBatch(batch, mapping, entityTypes, masks, pseudonymize,
"Dateinamen analysieren");
mapping = analyzed.mapping;
for (const { batch: part, result } of analyzed.results) {
const spans = spansBySegment(part, result.spans);
for (const segment of part.segments) {
const path = byPath.get(segment.key)!;
const found = toUtf16Offsets(segment.text, spans.get(path.key) ?? []).map((span, hitIndex) => ({
...span, id: `${path.key}:path:${hitIndex}`, file: path.key,
source: "Datei- oder Ordnername", kind: "path" as const,
context: path.value,
}));
path.hits = withoutWhitelistedHits(withoutPlaceholderHits(found, previousPlaceholders), whitelist);
hits.push(...path.hits);
if (hits.length > MAX_REVIEW_HITS) throw new Error("Zu viele Treffer. Bitte weniger Kategorien auswählen.");
}
}
}
return { drafts, retained, paths, mapping, previousMapping,