mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(views): construct source-location pages once (#16872)
This commit is contained in:
1 parent
2009922533
commit
c38551a79a
1 file changed
+9
-19
@@ -146,11 +146,11 @@ const tooLarge = (maxBytes: number, parentEvidenceId: string) =>
|
||||
},
|
||||
),
|
||||
);
|
||||
const withinBudget = (value: unknown, maxBytes: number) =>
|
||||
const viewBytes = (value: unknown, maxBytes: number) =>
|
||||
jsonValueByteLength(
|
||||
{ ...(value as Record<string, JsonValue>), view_digest: "0".repeat(64) },
|
||||
maxBytes,
|
||||
) <= maxBytes;
|
||||
);
|
||||
|
||||
type Report = z.output<typeof webSourceLocationResultSchema>;
|
||||
type LocationView = z.output<typeof webSourceLocationViewRequestSchema>;
|
||||
@@ -219,7 +219,7 @@ const projectSourceText = (
|
||||
match: selected,
|
||||
...page,
|
||||
};
|
||||
return withinBudget(result, view.max_bytes)
|
||||
return viewBytes(result, view.max_bytes) <= view.max_bytes
|
||||
? ok(result)
|
||||
: tooLarge(view.max_bytes, shared.parent_evidence_id);
|
||||
};
|
||||
@@ -237,7 +237,7 @@ const projectMatches = (
|
||||
...shared,
|
||||
coverage: pageViewCoverage(offset, 0, matches.length),
|
||||
};
|
||||
const build = () =>
|
||||
const result =
|
||||
view.kind === "summary"
|
||||
? {
|
||||
...common,
|
||||
@@ -252,20 +252,10 @@ const projectMatches = (
|
||||
source_location: context,
|
||||
items,
|
||||
};
|
||||
const base = build();
|
||||
// Reserve maximum numeric coverage widths once; row admission remains linear in returned rows.
|
||||
let bytes = jsonValueByteLength(
|
||||
{
|
||||
...base,
|
||||
view_digest: "0".repeat(64),
|
||||
coverage: {
|
||||
...common.coverage,
|
||||
examined: Number.MAX_SAFE_INTEGER,
|
||||
next_offset: Number.MAX_SAFE_INTEGER,
|
||||
},
|
||||
} as JsonValue,
|
||||
maxBytes,
|
||||
);
|
||||
result.coverage.examined = Number.MAX_SAFE_INTEGER;
|
||||
result.coverage.next_offset = Number.MAX_SAFE_INTEGER;
|
||||
let bytes = viewBytes(result, maxBytes);
|
||||
if (bytes > maxBytes) return tooLarge(maxBytes, shared.parent_evidence_id);
|
||||
for (
|
||||
let index = offset;
|
||||
@@ -284,8 +274,8 @@ const projectMatches = (
|
||||
items.push(item);
|
||||
bytes += added;
|
||||
}
|
||||
common.coverage = pageViewCoverage(offset, items.length, matches.length);
|
||||
return ok(build());
|
||||
result.coverage = pageViewCoverage(offset, items.length, matches.length);
|
||||
return ok(result);
|
||||
};
|
||||
/** Query authenticated source-location facts without reopening any selected artifact. */
|
||||
export const projectWebSourceLocationView = (
|
||||
|
||||
Reference in new issue
Block a user