mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
perf(views): O(limit) unfiltered paging and pickFields in api, endpoint, source, and trace views (#13794)
This commit is contained in:
1 parent
6cda340ec9
commit
ef21d8f406
4 files changed
+127
-128
No files matched your search
@@ -10,7 +10,6 @@ import {
|
||||
type ApiContract,
|
||||
} from "../apiContract/apiContract.js";
|
||||
import { apiContractViewRequestSchema } from "../apiContract/apiContractQuery.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import { err, ok } from "../result.js";
|
||||
import {
|
||||
createAnalysisViewResultReader,
|
||||
@@ -26,7 +25,7 @@ import {
|
||||
completeWithinViewCoverage,
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
import { selectViewRows } from "./selectViewRows.js";
|
||||
import { pickFields, selectViewRows } from "./selectViewRows.js";
|
||||
import { analysisViewInputError } from "./analysisViewErrors.js";
|
||||
|
||||
export const apiContractViewContextSchema = apiContractSchema.omit({
|
||||
@@ -66,14 +65,6 @@ const values = (selected: readonly string[] | undefined) =>
|
||||
selected === undefined ? undefined : new Set(selected);
|
||||
const admits = (selection: ReadonlySet<string> | undefined, value: string) =>
|
||||
selection === undefined || selection.has(value);
|
||||
const fieldsOf = (
|
||||
row: object,
|
||||
fields: readonly string[],
|
||||
): Record<string, JsonValue> => {
|
||||
const source = row as Record<string, JsonValue>;
|
||||
return Object.fromEntries(fields.map((field) => [field, source[field]!]));
|
||||
};
|
||||
|
||||
const selectOperations = (
|
||||
report: ApiContract,
|
||||
view: Extract<
|
||||
@@ -87,19 +78,29 @@ const selectOperations = (
|
||||
paths = values(view.paths),
|
||||
declared = values(view.declared_ids),
|
||||
states = values(view.states);
|
||||
const filtered =
|
||||
ids !== undefined ||
|
||||
keys !== undefined ||
|
||||
methods !== undefined ||
|
||||
paths !== undefined ||
|
||||
declared !== undefined ||
|
||||
states !== undefined;
|
||||
const fields = view.fields ?? ["method", "path", "declared_id"];
|
||||
return selectViewRows(
|
||||
report.operations,
|
||||
view,
|
||||
(row) =>
|
||||
admits(ids, row.operation_id) &&
|
||||
admits(keys, row.operation_key) &&
|
||||
admits(methods, row.method) &&
|
||||
admits(paths, row.path) &&
|
||||
admits(states, row.state) &&
|
||||
(declared === undefined ||
|
||||
(row.declared_id !== null && declared.has(row.declared_id))),
|
||||
filtered
|
||||
? (row) =>
|
||||
admits(ids, row.operation_id) &&
|
||||
admits(keys, row.operation_key) &&
|
||||
admits(methods, row.method) &&
|
||||
admits(paths, row.path) &&
|
||||
admits(states, row.state) &&
|
||||
(declared === undefined ||
|
||||
(row.declared_id !== null && declared.has(row.declared_id)))
|
||||
: undefined,
|
||||
(row) => ({
|
||||
...fieldsOf(row, view.fields ?? ["method", "path", "declared_id"]),
|
||||
...pickFields(row, fields),
|
||||
operation_id: row.operation_id,
|
||||
operation_key: row.operation_key,
|
||||
source_pointer: row.source_pointer,
|
||||
@@ -116,12 +117,13 @@ const selectRows = (
|
||||
if (view.collection === "operations") return selectOperations(report, view);
|
||||
if (view.collection === "path-item-references") {
|
||||
const ids = values(view.reference_ids);
|
||||
const fields = view.fields ?? ["path", "reference"];
|
||||
return selectViewRows(
|
||||
report.path_item_references,
|
||||
view,
|
||||
(row) => admits(ids, row.reference_id),
|
||||
ids === undefined ? undefined : (row) => ids.has(row.reference_id),
|
||||
(row) => ({
|
||||
...fieldsOf(row, view.fields ?? ["path", "reference"]),
|
||||
...pickFields(row, fields),
|
||||
reference_id: row.reference_id,
|
||||
source_pointer: row.source_pointer,
|
||||
state: row.state,
|
||||
@@ -130,12 +132,13 @@ const selectRows = (
|
||||
);
|
||||
}
|
||||
const codes = values(view.codes);
|
||||
const fields = view.fields ?? ["message"];
|
||||
return selectViewRows(
|
||||
report.diagnostics,
|
||||
view,
|
||||
(row) => admits(codes, row.code),
|
||||
codes === undefined ? undefined : (row) => codes.has(row.code),
|
||||
(row) => ({
|
||||
...fieldsOf(row, view.fields ?? ["message"]),
|
||||
...pickFields(row, fields),
|
||||
diagnostic_id: row.diagnostic_id,
|
||||
source_pointer: row.source_pointer,
|
||||
code: row.code,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import type { StaticObservedEndpointComparison } from "../javascript/staticObservedEndpointSchemas.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import {
|
||||
comparedStaticEndpointSchema,
|
||||
comparedObservedGroupSchema,
|
||||
@@ -21,7 +20,7 @@ import {
|
||||
completeWithinViewCoverage,
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
import { selectViewRows } from "./selectViewRows.js";
|
||||
import { pickFields, selectViewRows } from "./selectViewRows.js";
|
||||
import { analysisViewInputError } from "./analysisViewErrors.js";
|
||||
import { err, ok } from "../result.js";
|
||||
|
||||
@@ -83,11 +82,6 @@ const readReport = createAnalysisViewResultReader(
|
||||
);
|
||||
const set = (values: readonly string[] | undefined) =>
|
||||
values === undefined ? undefined : new Set(values);
|
||||
const fieldsOf = (row: object, fields: readonly string[]) => {
|
||||
const source = row as Record<string, JsonValue>;
|
||||
return Object.fromEntries(fields.map((field) => [field, source[field]!]));
|
||||
};
|
||||
|
||||
const selectComparisonRows = (
|
||||
report: StaticObservedEndpointComparison,
|
||||
view: z.output<typeof endpointComparisonViewRequestSchema>,
|
||||
@@ -100,25 +94,25 @@ const selectComparisonRows = (
|
||||
if (view.collection === "static-endpoints") {
|
||||
const ids = set(view.endpoint_ids),
|
||||
statuses = set(view.statuses);
|
||||
const fields = view.fields ?? [
|
||||
"method",
|
||||
"method_basis",
|
||||
"origin",
|
||||
"origin_basis",
|
||||
"path",
|
||||
"status",
|
||||
"reason",
|
||||
];
|
||||
selected = selectViewRows(
|
||||
static_endpoints,
|
||||
view,
|
||||
(row) =>
|
||||
(ids === undefined || ids.has(row.endpoint_id)) &&
|
||||
(statuses === undefined || statuses.has(row.status)),
|
||||
ids === undefined && statuses === undefined
|
||||
? undefined
|
||||
: (row) =>
|
||||
(ids === undefined || ids.has(row.endpoint_id)) &&
|
||||
(statuses === undefined || statuses.has(row.status)),
|
||||
(row) => ({
|
||||
...fieldsOf(
|
||||
row,
|
||||
view.fields ?? [
|
||||
"method",
|
||||
"method_basis",
|
||||
"origin",
|
||||
"origin_basis",
|
||||
"path",
|
||||
"status",
|
||||
"reason",
|
||||
],
|
||||
),
|
||||
...pickFields(row, fields),
|
||||
endpoint_id: row.endpoint_id,
|
||||
node_id: row.node_id,
|
||||
observation_id: row.observation_id,
|
||||
@@ -127,37 +121,40 @@ const selectComparisonRows = (
|
||||
} else if (view.collection === "observed-groups") {
|
||||
const ids = set(view.group_ids),
|
||||
statuses = set(view.statuses);
|
||||
const fields = view.fields ?? [
|
||||
"method",
|
||||
"origin",
|
||||
"path_template",
|
||||
"status",
|
||||
"reason",
|
||||
];
|
||||
selected = selectViewRows(
|
||||
observed_groups,
|
||||
view,
|
||||
(row) =>
|
||||
(ids === undefined || ids.has(row.group_id)) &&
|
||||
(statuses === undefined || statuses.has(row.status)),
|
||||
ids === undefined && statuses === undefined
|
||||
? undefined
|
||||
: (row) =>
|
||||
(ids === undefined || ids.has(row.group_id)) &&
|
||||
(statuses === undefined || statuses.has(row.status)),
|
||||
(row) => ({
|
||||
...fieldsOf(
|
||||
row,
|
||||
view.fields ?? [
|
||||
"method",
|
||||
"origin",
|
||||
"path_template",
|
||||
"status",
|
||||
"reason",
|
||||
],
|
||||
),
|
||||
...pickFields(row, fields),
|
||||
group_id: row.group_id,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
const endpoints = set(view.endpoint_ids),
|
||||
groups = set(view.group_ids);
|
||||
const fields = view.fields ?? ["basis", "supporting_record_ordinal"];
|
||||
selected = selectViewRows(
|
||||
matches,
|
||||
view,
|
||||
(row) =>
|
||||
(endpoints === undefined || endpoints.has(row.endpoint_id)) &&
|
||||
(groups === undefined || groups.has(row.group_id)),
|
||||
endpoints === undefined && groups === undefined
|
||||
? undefined
|
||||
: (row) =>
|
||||
(endpoints === undefined || endpoints.has(row.endpoint_id)) &&
|
||||
(groups === undefined || groups.has(row.group_id)),
|
||||
(row) => ({
|
||||
...fieldsOf(row, view.fields ?? ["basis", "supporting_record_ordinal"]),
|
||||
...pickFields(row, fields),
|
||||
match_id: row.match_id,
|
||||
endpoint_id: row.endpoint_id,
|
||||
group_id: row.group_id,
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
type PlaywrightTrace,
|
||||
} from "../playwrightTrace/playwrightTrace.js";
|
||||
import { playwrightTraceViewRequestSchema } from "../playwrightTrace/playwrightTraceQuery.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import { err, ok } from "../result.js";
|
||||
import {
|
||||
createAnalysisViewResultReader,
|
||||
@@ -32,7 +31,7 @@ import {
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
import { isImmutableJsonSnapshot } from "../immutableJson.js";
|
||||
import { selectViewRows } from "./selectViewRows.js";
|
||||
import { pickFields, selectViewRows } from "./selectViewRows.js";
|
||||
import { analysisViewInputError } from "./analysisViewErrors.js";
|
||||
|
||||
export const playwrightTraceViewContextSchema = playwrightTraceSchema
|
||||
@@ -111,13 +110,8 @@ const allows = (
|
||||
selection: ReadonlySet<string> | undefined,
|
||||
value: string | null,
|
||||
) => selection === undefined || (value !== null && selection.has(value));
|
||||
const fields = (row: object, selected: readonly string[]) =>
|
||||
Object.fromEntries(
|
||||
selected.map((key) => [key, (row as Record<string, JsonValue>)[key]!]),
|
||||
);
|
||||
type View = z.output<typeof playwrightTraceViewRequestSchema>;
|
||||
const eventFields = (
|
||||
row: PlaywrightTrace["events"][number],
|
||||
const createEventProjector = (
|
||||
view: Extract<View, { collection: "events" }>,
|
||||
) => {
|
||||
const selected = view.fields?.filter((field) => field !== "text_preview") ?? [
|
||||
@@ -132,25 +126,27 @@ const eventFields = (
|
||||
];
|
||||
const preview =
|
||||
view.fields === undefined || view.fields.includes("text_preview");
|
||||
let text_preview:
|
||||
| (z.output<typeof analysisTextPageItemSchema> & {
|
||||
coverage: z.output<typeof analysisViewCoverageSchema>;
|
||||
})
|
||||
| null = null;
|
||||
if (preview && row.text !== null) {
|
||||
const page = analysisTextPage(row.text, 0, 256, "Recorded event text");
|
||||
if (!page.ok) throw page.error;
|
||||
text_preview = { ...page.value.item, coverage: page.value.coverage };
|
||||
}
|
||||
return {
|
||||
...fields(row, selected),
|
||||
...(preview ? { text_preview } : {}),
|
||||
event_id: row.event_id,
|
||||
stream_id: row.stream_id,
|
||||
ordinal: row.ordinal,
|
||||
source: row.source,
|
||||
kind: row.kind,
|
||||
credential_redacted: row.credential_redacted,
|
||||
return (row: PlaywrightTrace["events"][number]) => {
|
||||
let text_preview:
|
||||
| (z.output<typeof analysisTextPageItemSchema> & {
|
||||
coverage: z.output<typeof analysisViewCoverageSchema>;
|
||||
})
|
||||
| null = null;
|
||||
if (preview && row.text !== null) {
|
||||
const page = analysisTextPage(row.text, 0, 256, "Recorded event text");
|
||||
if (!page.ok) throw page.error;
|
||||
text_preview = { ...page.value.item, coverage: page.value.coverage };
|
||||
}
|
||||
return {
|
||||
...pickFields(row, selected),
|
||||
...(preview ? { text_preview } : {}),
|
||||
event_id: row.event_id,
|
||||
stream_id: row.stream_id,
|
||||
ordinal: row.ordinal,
|
||||
source: row.source,
|
||||
kind: row.kind,
|
||||
credential_redacted: row.credential_redacted,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -236,19 +232,18 @@ const selectRows = (
|
||||
streams = values(view.stream_ids),
|
||||
kinds = values(view.kinds),
|
||||
calls = values(view.call_ids);
|
||||
const filtered =
|
||||
ids !== undefined ||
|
||||
streams !== undefined ||
|
||||
kinds !== undefined ||
|
||||
calls !== undefined;
|
||||
const matchEvent = (row: PlaywrightTrace["events"][number]): boolean =>
|
||||
allows(ids, row.event_id) &&
|
||||
allows(streams, row.stream_id) &&
|
||||
allows(kinds, row.kind) &&
|
||||
allows(calls, row.call_id);
|
||||
const projectEvent = (row: PlaywrightTrace["events"][number]) =>
|
||||
eventFields(row, view);
|
||||
if (
|
||||
ids !== undefined ||
|
||||
streams !== undefined ||
|
||||
kinds !== undefined ||
|
||||
calls !== undefined
|
||||
) {
|
||||
const projectEvent = createEventProjector(view);
|
||||
if (filtered) {
|
||||
const candidates =
|
||||
ids !== undefined
|
||||
? candidateIndices(report, report.events, "event_id", ids)
|
||||
@@ -266,19 +261,22 @@ const selectRows = (
|
||||
projectEvent,
|
||||
);
|
||||
}
|
||||
return selectViewRows(report.events, view, matchEvent, projectEvent);
|
||||
}
|
||||
return selectViewRows(report.events, view, matchEvent, projectEvent);
|
||||
return selectViewRows(report.events, view, undefined, projectEvent);
|
||||
}
|
||||
if (view.collection === "members") {
|
||||
const ids = values(view.member_ids),
|
||||
paths = values(view.paths);
|
||||
const filtered = ids !== undefined || paths !== undefined;
|
||||
const matchMember = (row: PlaywrightTrace["members"][number]): boolean =>
|
||||
allows(ids, row.member_id) && allows(paths, row.path);
|
||||
const memberFields = view.fields ?? [
|
||||
"declared_bytes",
|
||||
"declared_compressed_bytes",
|
||||
];
|
||||
const projectMember = (row: PlaywrightTrace["members"][number]) => ({
|
||||
...fields(
|
||||
row,
|
||||
view.fields ?? ["declared_bytes", "declared_compressed_bytes"],
|
||||
),
|
||||
...pickFields(row, memberFields),
|
||||
member_id: row.member_id,
|
||||
path: row.path,
|
||||
logical_path: row.logical_path,
|
||||
@@ -287,7 +285,7 @@ const selectRows = (
|
||||
decoded: row.decoded,
|
||||
limitations: row.limitations,
|
||||
});
|
||||
if (ids !== undefined || paths !== undefined) {
|
||||
if (filtered) {
|
||||
const candidates =
|
||||
ids !== undefined
|
||||
? candidateIndices(report, report.members, "member_id", ids)
|
||||
@@ -301,15 +299,21 @@ const selectRows = (
|
||||
projectMember,
|
||||
);
|
||||
}
|
||||
return selectViewRows(report.members, view, matchMember, projectMember);
|
||||
}
|
||||
return selectViewRows(report.members, view, matchMember, projectMember);
|
||||
return selectViewRows(report.members, view, undefined, projectMember);
|
||||
}
|
||||
if (view.collection === "streams") {
|
||||
const ids = values(view.stream_ids);
|
||||
const matchStream = (row: PlaywrightTrace["streams"][number]): boolean =>
|
||||
allows(ids, row.stream_id);
|
||||
const streamFields = view.fields ?? [
|
||||
"producer",
|
||||
"lines",
|
||||
"supported_events",
|
||||
];
|
||||
const projectStream = (row: PlaywrightTrace["streams"][number]) => ({
|
||||
...fields(row, view.fields ?? ["producer", "lines", "supported_events"]),
|
||||
...pickFields(row, streamFields),
|
||||
stream_id: row.stream_id,
|
||||
member_id: row.member_id,
|
||||
role: row.role,
|
||||
@@ -331,15 +335,17 @@ const selectRows = (
|
||||
matchStream,
|
||||
projectStream,
|
||||
);
|
||||
return selectViewRows(report.streams, view, matchStream, projectStream);
|
||||
}
|
||||
return selectViewRows(report.streams, view, matchStream, projectStream);
|
||||
return selectViewRows(report.streams, view, undefined, projectStream);
|
||||
}
|
||||
const codes = values(view.codes);
|
||||
const matchDiagnostic = (
|
||||
row: PlaywrightTrace["diagnostics"][number],
|
||||
): boolean => allows(codes, row.code);
|
||||
const diagnosticFields = view.fields ?? ["message"];
|
||||
const projectDiagnostic = (row: PlaywrightTrace["diagnostics"][number]) => ({
|
||||
...fields(row, view.fields ?? ["message"]),
|
||||
...pickFields(row, diagnosticFields),
|
||||
diagnostic_id: row.diagnostic_id,
|
||||
member_id: row.member_id,
|
||||
line: row.line,
|
||||
@@ -360,13 +366,14 @@ const selectRows = (
|
||||
matchDiagnostic,
|
||||
projectDiagnostic,
|
||||
);
|
||||
return selectViewRows(
|
||||
report.diagnostics,
|
||||
view,
|
||||
matchDiagnostic,
|
||||
projectDiagnostic,
|
||||
);
|
||||
}
|
||||
return selectViewRows(
|
||||
report.diagnostics,
|
||||
view,
|
||||
matchDiagnostic,
|
||||
projectDiagnostic,
|
||||
);
|
||||
return selectViewRows(report.diagnostics, view, undefined, projectDiagnostic);
|
||||
};
|
||||
const selectEventText = (
|
||||
report: PlaywrightTrace,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { z } from "zod";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import {
|
||||
sourceToBundleComparisonResultSchema,
|
||||
type SourceToBundleComparisonResult,
|
||||
@@ -18,7 +17,7 @@ import {
|
||||
completeWithinViewCoverage,
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
import { selectViewRows } from "./selectViewRows.js";
|
||||
import { pickFields, selectViewRows } from "./selectViewRows.js";
|
||||
|
||||
const mapping = sourceToBundleComparisonResultSchema.shape.items.element;
|
||||
const candidate = mapping.shape.candidates.element;
|
||||
@@ -98,15 +97,6 @@ const checkedReport = createAnalysisViewResultReader(
|
||||
);
|
||||
const selected = (values: readonly string[] | undefined) =>
|
||||
values === undefined ? undefined : new Set(values);
|
||||
const columns = (
|
||||
row: object,
|
||||
fields: readonly string[],
|
||||
): Record<string, JsonValue> => {
|
||||
const selected = new Set(fields);
|
||||
return Object.fromEntries(
|
||||
Object.entries(row).filter(([field]) => selected.has(field)),
|
||||
);
|
||||
};
|
||||
|
||||
/** Page facts owned by a complete comparison; page exhaustion does not upgrade source coverage. */
|
||||
export const projectSourceToBundleView = (
|
||||
@@ -167,6 +157,8 @@ export const projectSourceToBundleView = (
|
||||
const paths = selected(view.source_paths),
|
||||
ids = selected(view.mapping_ids),
|
||||
statuses = selected(view.statuses);
|
||||
const filtered =
|
||||
paths !== undefined || ids !== undefined || statuses !== undefined;
|
||||
const matches = (row: SourceToBundleComparisonResult["items"][number]) =>
|
||||
(paths === undefined || paths.has(row.source_path)) &&
|
||||
(ids === undefined || ids.has(row.mapping_id)) &&
|
||||
@@ -188,9 +180,9 @@ export const projectSourceToBundleView = (
|
||||
const page = selectViewRows(
|
||||
report.items,
|
||||
view,
|
||||
matches,
|
||||
filtered ? matches : undefined,
|
||||
(row, source_index) => ({
|
||||
...columns(
|
||||
...pickFields(
|
||||
{
|
||||
...row,
|
||||
source_index,
|
||||
@@ -210,7 +202,7 @@ export const projectSourceToBundleView = (
|
||||
items = [];
|
||||
total = 0;
|
||||
for (const [source_index, row] of report.items.entries()) {
|
||||
if (!matches(row)) continue;
|
||||
if (filtered && !matches(row)) continue;
|
||||
const start = Math.max(0, view.offset - total);
|
||||
const end = Math.min(
|
||||
row.candidates.length,
|
||||
@@ -225,7 +217,7 @@ export const projectSourceToBundleView = (
|
||||
) {
|
||||
const candidate = row.candidates[candidate_index]!;
|
||||
items.push({
|
||||
...columns(candidate, fields),
|
||||
...pickFields(candidate, fields),
|
||||
mapping_id: row.mapping_id,
|
||||
source_path: row.source_path,
|
||||
source_index,
|
||||
|
||||
Reference in new issue
Block a user