mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
refactor(views): reuse native reference page selection (#15604)
This commit is contained in:
1 parent
90c07a92d7
commit
4e07d98636
2 files changed
+46
-51
No files matched your search
@@ -22,6 +22,7 @@ import {
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
import { assertOwnedView, type AdmittedView } from "./analysisViewShape.js";
|
||||
import { selectByteBoundedViewRows } from "./byteBoundedViewRows.js";
|
||||
|
||||
export const nativeInstructionReferencesRequestSchema = z.strictObject({
|
||||
kind: z.literal("native-instruction-references"),
|
||||
@@ -124,31 +125,26 @@ export const projectNativeInstructionReferencesView = (
|
||||
coverage: WIDEST_VIEW_PAGE_COVERAGE,
|
||||
byte_limited: false,
|
||||
};
|
||||
let bytes = viewPageBytesWithDigest(header as JsonValue);
|
||||
if (bytes > PAGE_BYTES) return tooLarge();
|
||||
const rows: z.infer<typeof rowSchema>[] = [];
|
||||
let byteLimited = false;
|
||||
for (
|
||||
let index = view.offset;
|
||||
index < values.length && rows.length < view.limit;
|
||||
index++
|
||||
) {
|
||||
const row = { source_index: index, value: values[index]! };
|
||||
const size =
|
||||
jsonValueByteLength(row as JsonValue, PAGE_BYTES - bytes) +
|
||||
(rows.length === 0 ? 0 : 1);
|
||||
if (bytes + size > PAGE_BYTES) {
|
||||
byteLimited = true;
|
||||
break;
|
||||
}
|
||||
bytes += size;
|
||||
rows.push(row);
|
||||
}
|
||||
if (byteLimited && rows.length === 0) return tooLarge();
|
||||
const selectedRows = selectByteBoundedViewRows(
|
||||
values,
|
||||
view,
|
||||
{
|
||||
matches: undefined,
|
||||
project: (value, source_index) => ({ source_index, value }),
|
||||
},
|
||||
{
|
||||
parentEvidenceId: parent.evidenceId,
|
||||
envelope: header as JsonValue,
|
||||
facet: view.collection,
|
||||
},
|
||||
);
|
||||
if (!selectedRows.ok) return tooLarge();
|
||||
|
||||
const { rows, total, byte_limited } = selectedRows.value;
|
||||
return ok({
|
||||
...common,
|
||||
items: { state: "available" as const, rows },
|
||||
coverage: pageViewCoverage(view.offset, rows.length, values.length),
|
||||
byte_limited: byteLimited,
|
||||
coverage: pageViewCoverage(view.offset, rows.length, total),
|
||||
byte_limited,
|
||||
});
|
||||
};
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
WIDEST_VIEW_PAGE_COVERAGE,
|
||||
} from "./analysisViewPageBudget.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import { selectByteBoundedViewRows } from "./byteBoundedViewRows.js";
|
||||
import { jsonValueByteLength } from "../jsonValueByteLength.js";
|
||||
import {
|
||||
boundedViewLimitations,
|
||||
@@ -172,15 +173,36 @@ export const projectNativeProcedureReferencesView = (
|
||||
byte_limited: false,
|
||||
coverage: WIDEST_VIEW_PAGE_COVERAGE,
|
||||
};
|
||||
if (view.collection === "unresolved_calls") {
|
||||
const selectedRows = selectByteBoundedViewRows(
|
||||
source.unresolved_calls,
|
||||
view,
|
||||
{
|
||||
matches: undefined,
|
||||
project: (value, source_index) => ({ source_index, value }),
|
||||
},
|
||||
{
|
||||
parentEvidenceId: parent.evidenceId,
|
||||
envelope: header as JsonValue,
|
||||
facet: view.collection,
|
||||
},
|
||||
);
|
||||
if (!selectedRows.ok) return tooLarge();
|
||||
|
||||
const { rows, total, byte_limited } = selectedRows.value;
|
||||
return ok({
|
||||
...common,
|
||||
view,
|
||||
items: { collection: "unresolved_calls" as const, rows },
|
||||
byte_limited,
|
||||
coverage: pageViewCoverage(view.offset, rows.length, total),
|
||||
});
|
||||
}
|
||||
let bytes = viewPageBytesWithDigest(header as JsonValue);
|
||||
if (bytes > PAGE_BYTES) return tooLarge();
|
||||
const referenceRows: z.infer<typeof rowSchema>[] = [];
|
||||
const unresolvedRows: {
|
||||
source_index: number;
|
||||
value: z.infer<typeof unresolvedCallSchema>;
|
||||
}[] = [];
|
||||
let byteLimited = false;
|
||||
const offer = (row: JsonValue, accepted: number, extra = 0) => {
|
||||
const offer = (row: JsonValue, accepted: number, extra: number) => {
|
||||
const size =
|
||||
jsonValueByteLength(row, PAGE_BYTES - bytes) +
|
||||
(accepted > 0 ? 1 : 0) +
|
||||
@@ -192,29 +214,6 @@ export const projectNativeProcedureReferencesView = (
|
||||
bytes += size;
|
||||
return true;
|
||||
};
|
||||
if (view.collection === "unresolved_calls") {
|
||||
const calls = source.unresolved_calls;
|
||||
const end = Math.min(calls.length, view.offset + view.limit);
|
||||
for (let index = view.offset; index < end; index += 1) {
|
||||
const value = calls[index];
|
||||
if (value === undefined) break;
|
||||
const row = { source_index: index, value };
|
||||
if (!offer(row, unresolvedRows.length)) break;
|
||||
unresolvedRows.push(row);
|
||||
}
|
||||
if (byteLimited && unresolvedRows.length === 0) return tooLarge();
|
||||
return ok({
|
||||
...common,
|
||||
view,
|
||||
items: { collection: "unresolved_calls" as const, rows: unresolvedRows },
|
||||
byte_limited: byteLimited,
|
||||
coverage: pageViewCoverage(
|
||||
view.offset,
|
||||
unresolvedRows.length,
|
||||
calls.length,
|
||||
),
|
||||
});
|
||||
}
|
||||
const selected = canonicalJson(source.procedure);
|
||||
const endpoints: z.infer<typeof procedureIdentitySchema>[] = [];
|
||||
const endpointIndexes = new Map<string, number>();
|
||||
|
||||
Reference in new issue
Block a user